| 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 import logging | |
| 6 import re | 5 import re |
| 7 from path_utils import FormatKey | 6 from path_utils import FormatKey |
| 8 from third_party.handlebar import Handlebar | 7 from third_party.handlebar import Handlebar |
| 9 | 8 |
| 10 class IntroDataSource(object): | 9 class IntroDataSource(object): |
| 11 """This class fetches the intros for a given API. From this intro, a table | 10 """This class fetches the intros for a given API. From this intro, a table |
| 12 of contents dictionary is created, which contains the headings in the intro. | 11 of contents dictionary is created, which contains the headings in the intro. |
| 13 """ | 12 """ |
| 14 def __init__(self, cache_builder, base_paths): | 13 def __init__(self, cache_builder, base_paths): |
| 15 self._cache = cache_builder.build(self._MakeIntroDict) | 14 self._cache = cache_builder.build(self._MakeIntroDict) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 31 toc[-1]['subheadings'].append({ 'link': link, 'title': title }) | 30 toc[-1]['subheadings'].append({ 'link': link, 'title': title }) |
| 32 return { 'intro': Handlebar(intro), 'toc': toc , 'title': page_title } | 31 return { 'intro': Handlebar(intro), 'toc': toc , 'title': page_title } |
| 33 | 32 |
| 34 def __getitem__(self, key): | 33 def __getitem__(self, key): |
| 35 return self.get(key) | 34 return self.get(key) |
| 36 | 35 |
| 37 def get(self, key): | 36 def get(self, key): |
| 38 real_path = FormatKey(key) | 37 real_path = FormatKey(key) |
| 39 for base_path in self._base_paths: | 38 for base_path in self._base_paths: |
| 40 try: | 39 try: |
| 41 return self._cache.getFromFile(base_path + '/' + real_path) | 40 return self._cache.GetFromFile(base_path + '/' + real_path) |
| 42 except: | 41 except Exception: |
| 43 pass | 42 pass |
| 44 return None | 43 return None |
| OLD | NEW |