| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from path_utils import FormatKey | 5 from path_utils import FormatKey |
| 6 from third_party.handlebar import Handlebar | 6 from third_party.handlebar import Handlebar |
| 7 | 7 |
| 8 EXTENSIONS_URL = '/chrome/extensions' | 8 EXTENSIONS_URL = '/chrome/extensions' |
| 9 | 9 |
| 10 class TemplateDataSource(object): | 10 class TemplateDataSource(object): |
| 11 """This class fetches and compiles templates using the fetcher passed in with | 11 """This class fetches and compiles templates using the fetcher passed in with |
| 12 |cache_builder|. | 12 |cache_builder|. |
| 13 """ | 13 """ |
| 14 def __init__(self, | 14 def __init__(self, |
| 15 branch, | 15 branch, |
| 16 api_data_source, | 16 api_data_source, |
| 17 intro_data_source, | 17 intro_data_source, |
| 18 samples_data_source, |
| 18 cache_builder, | 19 cache_builder, |
| 19 base_paths): | 20 base_paths): |
| 20 self._branch_info = self._MakeBranchDict(branch) | 21 self._branch_info = self._MakeBranchDict(branch) |
| 21 self._static_resources = ((('/' + branch) if branch != 'local' else '') + | 22 self._static_resources = ((('/' + branch) if branch != 'local' else '') + |
| 22 '/static') | 23 '/static') |
| 23 self._api_data_source = api_data_source | 24 self._api_data_source = api_data_source |
| 24 self._intro_data_source = intro_data_source | 25 self._intro_data_source = intro_data_source |
| 26 self._samples_data_source = samples_data_source |
| 25 self._cache = cache_builder.build(self._LoadTemplate) | 27 self._cache = cache_builder.build(self._LoadTemplate) |
| 26 self._base_paths = base_paths | 28 self._base_paths = base_paths |
| 27 | 29 |
| 28 def _MakeBranchDict(self, branch): | 30 def _MakeBranchDict(self, branch): |
| 29 return { | 31 return { |
| 30 'showWarning': branch != 'stable', | 32 'showWarning': branch != 'stable', |
| 31 'branches': [ | 33 'branches': [ |
| 32 { 'name': 'Stable', 'path': EXTENSIONS_URL + '/stable' }, | 34 { 'name': 'Stable', 'path': EXTENSIONS_URL + '/stable' }, |
| 33 { 'name': 'Dev', 'path': EXTENSIONS_URL + '/dev' }, | 35 { 'name': 'Dev', 'path': EXTENSIONS_URL + '/dev' }, |
| 34 { 'name': 'Beta', 'path': EXTENSIONS_URL + '/beta' }, | 36 { 'name': 'Beta', 'path': EXTENSIONS_URL + '/beta' }, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 """ | 49 """ |
| 48 template = self.get(template_name) | 50 template = self.get(template_name) |
| 49 if not template: | 51 if not template: |
| 50 return '' | 52 return '' |
| 51 # TODO error handling | 53 # TODO error handling |
| 52 return template.render({ | 54 return template.render({ |
| 53 'apis': self._api_data_source, | 55 'apis': self._api_data_source, |
| 54 'branchInfo': self._branch_info, | 56 'branchInfo': self._branch_info, |
| 55 'intros': self._intro_data_source, | 57 'intros': self._intro_data_source, |
| 56 'partials': self, | 58 'partials': self, |
| 59 'samples': self._samples_data_source, |
| 57 'static': self._static_resources | 60 'static': self._static_resources |
| 58 }).text | 61 }).text |
| 59 | 62 |
| 60 def __getitem__(self, key): | 63 def __getitem__(self, key): |
| 61 return self.get(key) | 64 return self.get(key) |
| 62 | 65 |
| 63 def get(self, key): | 66 def get(self, key): |
| 64 real_path = FormatKey(key) | 67 real_path = FormatKey(key) |
| 65 for base_path in self._base_paths: | 68 for base_path in self._base_paths: |
| 66 try: | 69 try: |
| 67 return self._cache.get(base_path + '/' + real_path) | 70 return self._cache.getFromFile(base_path + '/' + real_path) |
| 68 except: | 71 except: |
| 69 pass | 72 pass |
| 70 return None | 73 return None |
| OLD | NEW |