Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9496)

Unified Diff: chrome/common/extensions/docs/server2/template_data_source.py

Issue 10689144: Extensions Docs Server: Samples zip files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better sample page Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/template_data_source.py
diff --git a/chrome/common/extensions/docs/server2/template_data_source.py b/chrome/common/extensions/docs/server2/template_data_source.py
index a19cf167cb96829daa555017a1070a022f07a12e..621191ca7491ced905af1d1c47a74eb1e6eb8354 100644
--- a/chrome/common/extensions/docs/server2/template_data_source.py
+++ b/chrome/common/extensions/docs/server2/template_data_source.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import re
from path_utils import FormatKey
from third_party.handlebar import Handlebar
@@ -16,6 +17,7 @@ class TemplateDataSource(object):
api_data_source,
intro_data_source,
cache_builder,
+ samples_path,
base_paths):
self._branch_info = self._MakeBranchDict(branch)
self._static_resources = ((('/' + branch) if branch != 'local' else '') +
@@ -23,7 +25,10 @@ class TemplateDataSource(object):
self._api_data_source = api_data_source
self._intro_data_source = intro_data_source
self._cache = cache_builder.build(self._LoadTemplate)
+ self._dir_cache = cache_builder.build(self._MakeSamplesList)
+ self._file_cache = cache_builder.build(lambda x: x)
self._base_paths = base_paths
+ self._samples_path = samples_path
def _MakeBranchDict(self, branch):
return {
@@ -37,6 +42,30 @@ class TemplateDataSource(object):
'current': branch
}
+ def _InsertApiFunctions(self, api_functions, js_file):
+ funcs = re.findall('(chrome\.[a-zA-Z0-9\.]+)',
+ self._file_cache.get(js_file))
+ return api_functions + list(set(funcs) - set(api_functions))
+
+ def _MakeSamplesList(self, files):
+ samples_list = []
+ for filename in files:
+ if filename.rsplit('/')[-1] == 'manifest.json':
+ # This is a little hacky, but it makes a sample page.
+ sample_path = filename.rsplit('/', 1)[-2]
+ sample_files = filter(lambda x: x.startswith(sample_path), files)
+ api_functions = []
+ for file_ in sample_files:
+ if file_.endswith('.js'):
+ api_functions = self._InsertApiFunctions(api_functions, file_)
+ samples_list.append({
+ 'name': filename.rsplit('/')[-2],
+ 'path': sample_path.split('/', 1)[1] + '.zip',
+ 'files': [f.replace(sample_path + '/', '') for f in sample_files],
+ 'api_functions': api_functions
+ })
+ return samples_list
+
def _LoadTemplate(self, template):
return Handlebar(template)
@@ -54,6 +83,7 @@ class TemplateDataSource(object):
'branchInfo': self._branch_info,
'intros': self._intro_data_source,
'partials': self,
+ 'samples': self._dir_cache.get(self._samples_path, True),
'static': self._static_resources
}).text

Powered by Google App Engine
This is Rietveld 408576698