Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/handler.py |
| diff --git a/chrome/common/extensions/docs/server2/handler.py b/chrome/common/extensions/docs/server2/handler.py |
| index 92e7c77e7c7c399ce7b59ccba2ababe006d84b6d..83a9ddd374c2796e0ff35a274fa3537bc722d68c 100644 |
| --- a/chrome/common/extensions/docs/server2/handler.py |
| +++ b/chrome/common/extensions/docs/server2/handler.py |
| @@ -48,17 +48,18 @@ DOCS_PATH = 'docs' |
| API_PATH = 'api' |
| INTRO_PATH = DOCS_PATH + '/server2/templates/intros' |
| ARTICLE_PATH = DOCS_PATH + '/server2/templates/articles' |
| -PUBLIC_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/public' |
| +APPS_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/apps' |
| +EXTENSIONS_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/extensions' |
|
not at google - send to devlin
2012/08/03 20:05:29
why do we need to split it like this, can't they b
cduvall
2012/08/03 22:38:00
Done.
|
| PRIVATE_TEMPLATE_PATH = DOCS_PATH + '/server2/templates/private' |
| EXAMPLES_PATH = DOCS_PATH + '/examples' |
| FULL_EXAMPLES_PATH = DOCS_PATH + '/' + EXAMPLES_PATH |
| # Global cache of instances because Handler is recreated for every request. |
| -SERVER_INSTANCES = {} |
| +SERVER_INSTANCES = { 'extensions': {}, 'apps': {} } |
| -def _GetInstanceForBranch(branch, local_path): |
| - if branch in SERVER_INSTANCES: |
| - return SERVER_INSTANCES[branch] |
| +def _GetInstanceForBranch(branch, local_path, doc_type): |
| + if branch in SERVER_INSTANCES[doc_type]: |
| + return SERVER_INSTANCES[doc_type][branch] |
| if branch == 'local': |
| file_system = LocalFileSystem(local_path) |
| else: |
| @@ -67,11 +68,15 @@ def _GetInstanceForBranch(branch, local_path): |
| file_system = MemcacheFileSystem(SubversionFileSystem(fetcher), |
| AppEngineMemcache(branch)) |
| + if doc_type == 'apps': |
| + public_path = APPS_TEMPLATE_PATH |
| + else: |
| + public_path = EXTENSIONS_TEMPLATE_PATH |
| cache_builder = FileSystemCache.Builder(file_system) |
| api_list_data_source = APIListDataSource(cache_builder, |
| file_system, |
| API_PATH, |
| - PUBLIC_TEMPLATE_PATH) |
| + public_path) |
| intro_data_source = IntroDataSource(cache_builder, |
| [INTRO_PATH, ARTICLE_PATH]) |
| samples_data_source_factory = SamplesDataSource.Factory(branch, |
| @@ -83,22 +88,23 @@ def _GetInstanceForBranch(branch, local_path): |
| samples_data_source_factory) |
| template_data_source_factory = TemplateDataSource.Factory( |
| branch, |
| + doc_type, |
| api_data_source_factory, |
| api_list_data_source, |
| intro_data_source, |
| samples_data_source_factory, |
| cache_builder, |
| - PUBLIC_TEMPLATE_PATH, |
| + public_path, |
| PRIVATE_TEMPLATE_PATH) |
| example_zipper = ExampleZipper(file_system, |
| cache_builder, |
| DOCS_PATH, |
| EXAMPLES_PATH) |
| - SERVER_INSTANCES[branch] = ServerInstance( |
| + SERVER_INSTANCES[doc_type][branch] = ServerInstance( |
| template_data_source_factory, |
| example_zipper, |
| cache_builder) |
| - return SERVER_INSTANCES[branch] |
| + return SERVER_INSTANCES[doc_type][branch] |
| def _GetURLFromBranch(branch): |
| if branch == 'trunk': |
| @@ -110,31 +116,40 @@ class Handler(webapp.RequestHandler): |
| self._local_path = local_path |
| super(Handler, self).__init__(request, response) |
| - def _NavigateToPath(self, path): |
| + def _NavigateToPath(self, path, doc_type): |
| channel_name, real_path = BRANCH_UTILITY.SplitChannelNameFromPath(path) |
| branch = BRANCH_UTILITY.GetBranchNumberForChannelName(channel_name) |
| if real_path == '': |
| real_path = 'index.html' |
| # TODO: This leaks Server instances when branch bumps. |
| - _GetInstanceForBranch(branch, self._local_path).Get(real_path, |
| - self.request, |
| - self.response) |
| + _GetInstanceForBranch(branch, self._local_path, doc_type).Get(real_path, |
| + self.request, |
| + self.response) |
| def get(self): |
| path = self.request.path |
| if '_ah/warmup' in path: |
| logging.info('Warmup request.') |
| if DEFAULT_BRANCH != 'local': |
| - self._NavigateToPath('trunk/samples.html') |
| - self._NavigateToPath('dev/samples.html') |
| - self._NavigateToPath('beta/samples.html') |
| - self._NavigateToPath('stable/samples.html') |
| + self._NavigateToPath('trunk/samples.html', 'extensions') |
| + self._NavigateToPath('dev/samples.html', 'extensions') |
| + self._NavigateToPath('beta/samples.html', 'extensions') |
| + self._NavigateToPath('stable/samples.html', 'extensions') |
| return |
| # Redirect paths like "directory" to "directory/". This is so relative file |
| # paths will know to treat this as a directory. |
| if os.path.splitext(path)[1] == '' and path[-1] != '/': |
| self.redirect(path + '/') |
| - path = path.replace('/chrome/extensions/', '') |
| + path = path.replace('/chrome/', '').lstrip('/') |
| + if path.startswith('extensions/'): |
| + path = path[len('extensions/'):] |
| + doc_type = 'extensions' |
| + elif path.startswith('apps/'): |
| + path = path[len('apps/'):] |
| + doc_type = 'apps' |
| + else: |
| + doc_type = 'extensions' |
| + |
| path = path.strip('/') |
| - self._NavigateToPath(path) |
| + self._NavigateToPath(path, doc_type) |