diff options
author | kurrik@chromium.org <kurrik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-05 19:49:36 +0000 |
---|---|---|
committer | kurrik@chromium.org <kurrik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-05 19:49:36 +0000 |
commit | 389509acdf508b1b4014406f55261ee8cbac4b3e (patch) | |
tree | ab4e79348aed11d81788ea3356dc22a507c38cee /chrome/common/extensions/docs/build/build.py | |
parent | d50c2c4917a34d27e2bda8eeb47a185a9bcf3ed3 (diff) | |
download | chromium_src-389509acdf508b1b4014406f55261ee8cbac4b3e.zip chromium_src-389509acdf508b1b4014406f55261ee8cbac4b3e.tar.gz chromium_src-389509acdf508b1b4014406f55261ee8cbac4b3e.tar.bz2 |
Change the existing extension samples page to an automatically-generated searchable directory.
* Fixes a typo in the maps_app sample that prevents the manifest from being parsed as valid JSON.
* Adds code to build a samples.json file in the documentation root, for use by the jstemplate docs rendering process.
* Adds build/sample.py, a class which parses an individual sample's metadata out of the filesystem
* Adds css/samples.css for directory-specific styles (could be merged into base styles if this is an issue)
* Adds images/sample-default-icon.png for samples which don't have 128px icons.
* Adds js/sample_search.js as the source for the sample search code (was difficult to escape this through the JSTemplate code without being in a different file).
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/2957009
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55111 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/extensions/docs/build/build.py')
-rwxr-xr-x | chrome/common/extensions/docs/build/build.py | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/chrome/common/extensions/docs/build/build.py b/chrome/common/extensions/docs/build/build.py index 509b9c2..f0d1b96 100755 --- a/chrome/common/extensions/docs/build/build.py +++ b/chrome/common/extensions/docs/build/build.py @@ -21,12 +21,14 @@ _base_dir = os.path.normpath(_build_dir + "/..") _static_dir = _base_dir + "/static" _js_dir = _base_dir + "/js" _template_dir = _base_dir + "/template" +_samples_dir = _base_dir + "/examples" _extension_api_dir = os.path.normpath(_base_dir + "/../api") _extension_api_json = _extension_api_dir + "/extension_api.json" _api_template_html = _template_dir + "/api_template.html" _page_shell_html = _template_dir + "/page_shell.html" _generator_html = _build_dir + "/generator.html" +_samples_json = _base_dir + "/samples.json" _expected_output_preamble = "<!DOCTYPE html>" _expected_output_postamble = "</body></html>" @@ -36,6 +38,9 @@ _expected_output_postamble = "</body></html>" sys.path.append(os.path.normpath(_base_dir + "/../../../../third_party")) import simplejson as json +from directory import Sample +from directory import ApiManifest +from directory import SamplesManifest def RenderPage(name, test_shell): """ @@ -132,22 +137,6 @@ def FindTestShell(): "Searched: \n" + "\n".join(search_locations) + "\n" + "To specify a path to test_shell use --test-shell-path") -def GetAPIModuleNames(): - try: - contents = open(_extension_api_json, 'r').read() - except IOError, msg: - raise Exception("Failed to read the file that defines the extensions API. " - "The specific error was: %s." % msg) - - try: - extension_api = json.loads(contents, encoding="ASCII") - except ValueError, msg: - raise Exception("File %s has a syntax error: %s" % - (_extension_api_json, msg)) - # Exclude modules with a "nodoc" property. - return set(module['namespace'].encode() for module in extension_api - if "nodoc" not in module) - def GetStaticFileNames(): static_files = os.listdir(_static_dir) return set(os.path.splitext(file_name)[0] @@ -162,6 +151,7 @@ def main(): parser = OptionParser() parser.add_option("--test-shell-path", dest="test_shell_path") + parser.add_option("--page-name", dest="page_name") (options, args) = parser.parse_args() if (options.test_shell_path and os.path.isfile(options.test_shell_path)): @@ -169,15 +159,30 @@ def main(): else: test_shell = FindTestShell() + # Load the manifest of existing API Methods + api_manifest = ApiManifest(_extension_api_json) + # Read static file names static_names = GetStaticFileNames() # Read module names - module_names = GetAPIModuleNames() + module_names = api_manifest.getModuleNames() # All pages to generate page_names = static_names | module_names + # Allow the user to render a single page if they want + if options.page_name: + if options.page_name in page_names: + page_names = [options.page_name] + else: + raise Exception("--page-name argument must be one of %s." % + ', '.join(sorted(page_names))) + + # Render a manifest file containing metadata about all the extension samples + samples_manifest = SamplesManifest(_samples_dir, _base_dir, api_manifest) + samples_manifest.writeToFile(_samples_json) + modified_files = [] for page in page_names: modified_file = RenderPage(page, test_shell) |