Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 40 if tag in ['h1', 'h2', 'h3']: | 40 if tag in ['h1', 'h2', 'h3']: |
| 41 self._recent_tag = None | 41 self._recent_tag = None |
| 42 | 42 |
| 43 def handle_data(self, data): | 43 def handle_data(self, data): |
| 44 if self._recent_tag is None: | 44 if self._recent_tag is None: |
| 45 return | 45 return |
| 46 if self._recent_tag == 'h1': | 46 if self._recent_tag == 'h1': |
| 47 if self.page_title is None: | 47 if self.page_title is None: |
| 48 self.page_title = data | 48 self.page_title = data |
| 49 else: | 49 else: |
| 50 self.page_title += data | 50 self.page_title += data |
|
not at google - send to devlin
2012/07/25 01:44:14
see previous comment about this?
(i.e. remove els
cduvall
2012/07/25 03:19:26
The else clause is needed because sometimes the da
| |
| 51 elif self._recent_tag in ['h2', 'h3']: | 51 elif self._recent_tag in ['h2', 'h3']: |
| 52 self._current_heading['title'] += data | 52 self._current_heading['title'] += data |
| 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 |