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 | 5 import logging |
6 | 6 |
7 from HTMLParser import HTMLParser | 7 from HTMLParser import HTMLParser |
8 | 8 |
9 from path_utils import FormatKey | 9 from path_utils import FormatKey |
10 from third_party.handlebar import Handlebar | 10 from third_party.handlebar import Handlebar |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 class IntroDataSource(object): | 54 class IntroDataSource(object): |
55 """This class fetches the intros for a given API. From this intro, a table | 55 """This class fetches the intros for a given API. From this intro, a table |
56 of contents dictionary is created, which contains the headings in the intro. | 56 of contents dictionary is created, which contains the headings in the intro. |
57 """ | 57 """ |
58 def __init__(self, cache_builder, base_paths): | 58 def __init__(self, cache_builder, base_paths): |
59 self._cache = cache_builder.build(self._MakeIntroDict) | 59 self._cache = cache_builder.build(self._MakeIntroDict) |
60 self._base_paths = base_paths | 60 self._base_paths = base_paths |
61 | 61 |
62 def _MakeIntroDict(self, intro): | 62 def _MakeIntroDict(self, intro): |
63 try: | 63 parser = _IntroParser() |
64 parser = _IntroParser() | 64 parser.feed(intro) |
65 parser.feed(intro) | 65 return { |
66 return { | 66 'intro': Handlebar(intro), |
67 'intro': Handlebar(intro), | 67 'toc': parser.toc, |
68 'toc': parser.toc, | 68 'title': parser.page_title |
69 'title': parser.page_title | 69 } |
70 } | |
71 except Exception as e: | |
72 logging.info(e) | |
73 | 70 |
74 def __getitem__(self, key): | 71 def __getitem__(self, key): |
75 return self.get(key) | 72 return self.get(key) |
76 | 73 |
77 def get(self, key): | 74 def get(self, key): |
78 real_path = FormatKey(key) | 75 real_path = FormatKey(key) |
79 for base_path in self._base_paths: | 76 for base_path in self._base_paths: |
80 try: | 77 try: |
81 return self._cache.GetFromFile(base_path + '/' + real_path) | 78 return self._cache.GetFromFile(base_path + '/' + real_path) |
82 except Exception: | 79 except Exception: |
83 pass | 80 pass |
84 return None | 81 return None |
OLD | NEW |