3c4d1fe8d1f6de254833c930da1fd66bbef7f13b
6 # Pull options reference JSON out of dygraph.js
9 for line
in file('dygraph.js'):
12 elif '</JSON>' in line
:
17 # TODO(danvk): better errors here.
21 # Go through the tests and find uses of each option.
23 docs
[opt
]['tests'] = []
25 # This is helpful for differentiating uses of options like 'width' and 'height'
26 # from appearances of identically-named options in CSS.
28 """Really primitive method to find text inside of {..} braces.
29 Doesn't work if there's an unmatched brace in a string, e.g. '{'. """
41 # Find text followed by a colon. These won't all be options, but those that
42 # have the same name as a Dygraph option probably will be.
43 prop_re
= re
.compile(r
'\b([a-zA-Z0-9]+):')
44 for test_file
in glob
.glob('tests/*.html'):
45 braced_html
= find_braces(file(test_file
).read())
46 ms
= re
.findall(prop_re
, braced_html
)
48 if opt
in docs
and test_file
not in docs
[opt
]['tests']:
49 docs
[opt
]['tests'].append(test_file
)
51 # Extract a labels list.
53 for nu
, opt
in docs
.iteritems():
54 for label
in opt
['labels']:
55 if label
not in labels
:
61 <title>Dygraphs Options Reference</title>
62 <style type="text/css">
72 print 'Options categories:\n'
74 for label
in sorted(labels
):
75 print ' <li><a href="#%s">%s</a>\n' %
(label
, label
)
79 """Takes 'tests/demo.html' -> 'demo'"""
80 return f
.replace('tests/', '').replace('.html', '')
82 for label
in sorted(labels
):
83 print '<a name="%s"><h2>%s</h2>\n' %
(label
, label
)
85 for opt_name
in sorted(docs
.keys()):
87 if label
not in opt
['labels']: continue
90 examples_html
= '<font color=red>NONE</font>'
92 examples_html
= ' '.join(
93 '<a href="%s">%s</a>' %
(f
, name(f
)) for f
in tests
)
96 <p class='option'><b>%(name)s</b><br/>
98 <i>Type: %(type)s<br/>
99 Default: %(default)s</i><br/>
100 Examples: %(examples_html)s<br/>
102 """ %
{ 'name': opt_name
,
104 'default': opt
['default'],
105 'desc': opt
['description'],
106 'examples_html': examples_html
}
109 # This page was super-helpful:
110 # http://jsbeautifier.org/