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
)
52 """Takes 'tests/demo.html' -> 'demo'"""
53 return f
.replace('tests/', '').replace('.html', '')
55 for opt_name
in sorted(docs
.keys()):
59 examples_html
= '<font color=red>NONE</font>'
61 examples_html
= ' '.join(
62 '<a href="%s">%s</a>' %
(f
, name(f
)) for f
in tests
)
65 <p><b>%(name)s</b><br/>
67 <i>Type: %(type)s<br/>
68 Default: %(default)s</i><br/>
69 Examples: %(examples_html)s<br/>
71 """ %
{ 'name': opt_name
,
73 'default': opt
['default'],
74 'desc': opt
['description'],
75 'examples_html': examples_html
}