Index: chrome/common/extensions/docs/server2/intro_data_source.py |
diff --git a/chrome/common/extensions/docs/server2/intro_data_source.py b/chrome/common/extensions/docs/server2/intro_data_source.py |
index 14315ad784ed4b9026699b46a986c3f166278ee1..198f9200ce6dd3a79f35aa8987e8c131e95f1fa9 100644 |
--- a/chrome/common/extensions/docs/server2/intro_data_source.py |
+++ b/chrome/common/extensions/docs/server2/intro_data_source.py |
@@ -3,11 +3,11 @@ |
# found in the LICENSE file. |
from HTMLParser import HTMLParser |
-import logging |
import re |
from docs_server_utils import FormatKey |
from file_system import FileNotFoundError |
+import file_system_cache as fs_cache |
from third_party.handlebar import Handlebar |
class _IntroParser(HTMLParser): |
@@ -53,23 +53,32 @@ class _IntroParser(HTMLParser): |
self._current_heading['title'] += data |
class IntroDataSource(object): |
+ class Factory(object): |
+ def __init__(self, cache_builder, base_paths): |
+ self._cache = cache_builder.build(self._MakeIntroDict, |
+ fs_cache.FS_CACHE_INTRO) |
+ self._base_paths = base_paths |
+ self._intro_regex = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL) |
not at google - send to devlin
2012/08/20 05:27:10
nit: doesn't need to be an instance variable?
cduvall
2012/08/20 21:28:09
Done.
|
+ |
+ def _MakeIntroDict(self, intro): |
+ parser = _IntroParser() |
+ parser.feed(intro) |
+ intro = re.sub(self._intro_regex, '', intro, count=1) |
+ return { |
+ 'intro': Handlebar(intro), |
+ 'toc': parser.toc, |
+ 'title': parser.page_title |
+ } |
+ |
+ def Create(self): |
+ return IntroDataSource(self._cache, self._base_paths) |
+ |
"""This class fetches the intros for a given API. From this intro, a table |
of contents dictionary is created, which contains the headings in the intro. |
""" |
- def __init__(self, cache_builder, base_paths): |
- self._cache = cache_builder.build(self._MakeIntroDict) |
+ def __init__(self, cache, base_paths): |
+ self._cache = cache |
self._base_paths = base_paths |
- self._intro_regex = re.compile('<h1[^>.]*?>.*?</h1>', flags=re.DOTALL) |
- |
- def _MakeIntroDict(self, intro): |
- parser = _IntroParser() |
- parser.feed(intro) |
- intro = re.sub(self._intro_regex, '', intro, count=1) |
- return { |
- 'intro': Handlebar(intro), |
- 'toc': parser.toc, |
- 'title': parser.page_title |
- } |
def __getitem__(self, key): |
return self.get(key) |