| 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>There's a hosted version of dygraphs on <a href="https://cdnjs.com/libraries/dygraph">cdnjs.com</a>:</p> |
| 53 | |
| 54 | <pre><script src="//cdnjs.cloudflare.com/ajax/libs/dygraph/%(version)s/dygraph-combined.js"></script></pre> |
| 55 | |
| 56 | <p>You can install dygraphs using <a href="https://www.npmjs.org/package/dygraphs">NPM</a> or <a href="http://bower.io/search/?q=dygraphs">Bower</a>.</p> |
| 57 | |
| 58 | <p>To install using NPM:</p> |
| 59 | <pre>$ npm install dygraphs |
| 60 | # dygraphs is now in node_modules/dygraphs/dygraph-combined.js</pre> |
| 61 | |
| 62 | <p>To install using bower:</p> |
| 63 | <pre>$ bower install dygraphs |
| 64 | # dygraphs is now in bower_components/dygraphs/dygraph-combined.js</pre> |
| 65 | |
| 66 | <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> |
| 67 | |
| 68 | <p>To generate your own minified JS, run:</p> |
| 69 | |
| 70 | <pre>git clone https://github.com/danvk/dygraphs.git |
| 71 | ./generate-combined.sh |
| 72 | </pre> |
| 73 | |
| 74 | <p>This will create a dygraph.min.js file in the dygraphs directory.</p> |
| 75 | |
| 76 | <p>You may also download files for previously-released versions:</p> |
| 77 | |
| 78 | <ul> |
| 79 | %(previous_lis)s |
| 80 | </ul> |
| 81 | |
| 82 | <p>See <a href="/versions.html">Version History</a> for more information on each release.</p> |
| 83 | |
| 84 | |
| 85 | <!--#include virtual="footer.html" --> |
| 86 | ''' % { |
| 87 | 'version': releases[0]['version'], |
| 88 | 'current_html': current_html, |
| 89 | 'previous_lis': '\n'.join(previous_lis) |
| 90 | } |