Chromium Code Reviews| 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 2c0774801c6546002f8c8001cbae74cbb3cd9ff7..0f95088187b5f5001003092e2b697424ffe89e29 100644 |
| --- a/chrome/common/extensions/docs/server2/template_data_source.py |
| +++ b/chrome/common/extensions/docs/server2/template_data_source.py |
| @@ -2,6 +2,8 @@ |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| +import logging |
| + |
| from path_utils import FormatKey |
| from third_party.handlebar import Handlebar |
| @@ -41,7 +43,8 @@ class TemplateDataSource(object): |
| intro_data_source, |
| samples_data_source, |
| cache_builder, |
| - base_paths): |
| + public_template_path, |
| + private_template_path): |
| self._branch_info = _MakeBranchDict(branch) |
| self._static_resources = ((('/' + branch) if branch != 'local' else '') + |
| '/static') |
| @@ -49,7 +52,8 @@ class TemplateDataSource(object): |
| self._intro_data_source = intro_data_source |
| self._samples_data_source = samples_data_source |
| self._cache = cache_builder.build(Handlebar) |
| - self._base_paths = base_paths |
| + self._public_template_path = public_template_path |
| + self._private_template_path = private_template_path |
| def Create(self, request): |
| """ Returns a new TemplateDataSource bound to |request|. |
| @@ -60,7 +64,8 @@ class TemplateDataSource(object): |
| self._intro_data_source, |
| self._samples_data_source, |
| self._cache, |
| - self._base_paths, |
| + self._public_template_path, |
| + self._private_template_path, |
| request) |
| def __init__(self, |
| @@ -70,7 +75,8 @@ class TemplateDataSource(object): |
| intro_data_source, |
| samples_data_source, |
| cache, |
| - base_paths, |
| + public_template_path, |
| + private_template_path, |
| request): |
| self._branch_info = branch_info |
| self._static_resources = static_resources |
| @@ -78,7 +84,8 @@ class TemplateDataSource(object): |
| self._intro_data_source = intro_data_source |
| self._samples_data_source = samples_data_source |
| self._cache = cache |
| - self._base_paths = base_paths |
| + self._public_template_path = public_template_path |
| + self._private_template_path = private_template_path |
| self._request = request |
| def Render(self, template_name): |
| @@ -86,7 +93,7 @@ class TemplateDataSource(object): |
| the partial templates needed from |self._cache|. Partials are retrieved |
| from the TemplateDataSource with the |get| method. |
| """ |
| - template = self.get(template_name) |
| + template = self.get(template_name, self._public_template_path) |
| if not template: |
| return '' |
| # TODO error handling |
| @@ -102,11 +109,14 @@ class TemplateDataSource(object): |
| def __getitem__(self, key): |
| return self.get(key) |
| - def get(self, key): |
| + def get(self, key, use_path=None): |
|
not at google - send to devlin
2012/07/23 13:13:27
Have two methods rather than overloading, like
cduvall
2012/07/23 19:04:41
Done.
|
| real_path = FormatKey(key) |
| - for base_path in self._base_paths: |
| - try: |
| - return self._cache.GetFromFile(base_path + '/' + real_path) |
| - except Exception: |
| - pass |
| - return None |
| + if use_path is None: |
| + base_path = self._private_template_path |
| + else: |
| + base_path = use_path |
| + try: |
| + return self._cache.GetFromFile(base_path + '/' + real_path) |
| + except Exception as e: |
| + logging.warn(e) |
| + return None |