| 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Generates docs/download.html |
| 4 | # Run: |
| 5 | # ./generate-download.py > docs/download.html |
| 6 | |
| 7 | import json |
| 8 | |
| 9 | releases = json.load(file('releases.json')) |
| 10 | |
| 11 | def file_links(release): |
| 12 | v = release['version'] |
| 13 | return ['<a href="%(v)s/%(f)s">%(f)s</a>' % { |
| 14 | 'f': f, 'v': v} for f in release['files']] |
| 15 | |
| 16 | |
| 17 | # Validation of releases.json |
| 18 | for idx, release in enumerate(releases): |
| 19 | if idx == 0: continue |
| 20 | assert 'version' in release, 'Release missing version: %s' % release |
| 21 | assert 'files' in release, 'Release missing files: %s' % release |
| 22 | assert release['version'] < releases[idx - 1]['version'], ( |
| 23 | 'Releases should be in reverse chronological order in releases.json') |
| 24 | |
| 25 | current_html = '<p>' + ('</p><p>'.join(file_links(releases[0]))) + '</p>' |
| 26 | |
| 27 | |
| 28 | previous_lis = [] |
| 29 | for release in releases[1:]: |
| 30 | previous_lis.append('<li>%(v)s: %(files)s (<a href="%(v)s/">%(v)s docs</a>)' % { |
| 31 | 'v': release['version'], |
| 32 | 'files': ', '.join(file_links(release)) |
| 33 | }) |
| 34 | |
| 35 | |
| 36 | print ''' |
| 37 | <!--#include virtual="header.html" --> |
| 38 | |
| 39 | <!-- |
| 40 | DO NOT EDIT THIS FILE! |
| 41 | |
| 42 | This file is generated by generate-download.py. |
| 43 | --> |
| 44 | |
| 45 | <script src="modernizr.custom.18445.js"></script> |
| 46 | <p>The current version of dygraphs is <b>%(version)s</b>. Most users will want to download minified files for this version:</p> |
| 47 | |
| 48 | <div id="current-release" class="panel"> |
| 49 | %(current_html)s |
| 50 | </div> |
| 51 | |
| 52 | <p>For dev (non-minified) JS, see <a href="https://github.com/danvk/dygraphs/blob/master/dygraph-dev.js">dygraph-dev.js</a> on <a href="https://github.com/danvk/dygraphs/">github</a>.</a> |
| 53 | |
| 54 | <p>To generate your own minified JS, run:</p> |
| 55 | |
| 56 | <pre>git clone https://github.com/danvk/dygraphs.git |
| 57 | ./generate-combined.sh |
| 58 | </pre> |
| 59 | |
| 60 | <p>This will create a dygraph.min.js file in the dygraphs directory.</p> |
| 61 | |
| 62 | <p>You may also download files for previously-released versions:</p> |
| 63 | |
| 64 | <ul> |
| 65 | %(previous_lis)s |
| 66 | </ul> |
| 67 | |
| 68 | <p>See <a href="/versions.html">Version History</a> for more information on each release.</p> |
| 69 | |
| 70 | |
| 71 | <!--#include virtual="footer.html" --> |
| 72 | ''' % { |
| 73 | 'version': releases[0]['version'], |
| 74 | 'current_html': current_html, |
| 75 | 'previous_lis': '\n'.join(previous_lis) |
| 76 | } |