X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=generate-documentation.py;h=1a66689371506fc59d0c4c180bb28e5af8757914;hb=7d8320a97033e4ed8968d12b513bfb7d104c9528;hp=2f91503500fee20986a72c4980a03b388b341255;hpb=bbfb84f2a5e0fbb5259fab16f0785a5806c5bf8d;p=dygraphs.git diff --git a/generate-documentation.py b/generate-documentation.py index 2f91503..1a66689 100755 --- a/generate-documentation.py +++ b/generate-documentation.py @@ -1,9 +1,10 @@ -#!/usr/bin/python +#!/usr/bin/env python # Generate docs/options.html -import json import glob +import json +import os import re import sys @@ -30,6 +31,7 @@ docs = json.loads(js) # Go through the tests and find uses of each option. for opt in docs: docs[opt]['tests'] = [] + docs[opt]['gallery'] = [] # This is helpful for differentiating uses of options like 'width' and 'height' # from appearances of identically-named options in CSS. @@ -47,20 +49,32 @@ def find_braces(txt): level -= 1 return out -# Find text followed by a colon. These won't all be options, but those that -# have the same name as a Dygraph option probably will be. -prop_re = re.compile(r'\b([a-zA-Z0-9]+) *:') -tests = debug_tests or glob.glob('tests/*.html') -for test_file in tests: - braced_html = find_braces(file(test_file).read()) - if debug_tests: - print braced_html - - ms = re.findall(prop_re, braced_html) - for opt in ms: - if debug_tests: print '\n'.join(ms) - if opt in docs and test_file not in docs[opt]['tests']: - docs[opt]['tests'].append(test_file) +def search_files(type, files): + # Find text followed by a colon. These won't all be options, but those that + # have the same name as a Dygraph option probably will be. + prop_re = re.compile(r'\b([a-zA-Z0-9]+) *:') + for test_file in files: + if os.path.isfile(test_file): # Basically skips directories + text = file(test_file).read() + + # Hack for slipping past gallery demos that have title in their attributes + # so they don't appear as reasons for the demo to have 'title' options. + if type == "gallery": + idx = text.find("function(") + if idx >= 0: + text = text[idx:] + braced_html = find_braces(text) + if debug_tests: + print braced_html + + ms = re.findall(prop_re, braced_html) + for opt in ms: + if debug_tests: print '\n'.join(ms) + if opt in docs and test_file not in docs[opt][type]: + docs[opt][type].append(test_file) + +search_files("tests", glob.glob("tests/*.html")) +search_files("gallery", glob.glob("gallery/*.js")) #TODO add grep "Gallery.register\(" if debug_tests: sys.exit(0) @@ -71,7 +85,7 @@ for nu, opt in docs.iteritems(): if label not in labels: labels.append(label) -print """ +print """ Dygraphs Options Reference @@ -80,6 +94,9 @@ print """ p.option { padding-left: 25px; } + div.parameters { + padding-left: 15px; + } #nav { position: fixed; } @@ -92,7 +109,7 @@ print """ """ print """ -