Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8189)

Unified Diff: chrome/common/extensions/docs/server2/intro_data_source.py

Issue 10750017: Extensions Docs Server: Intro data source (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..85fab3abc47d090930382fffa5c0bb6589fda302
--- /dev/null
+++ b/chrome/common/extensions/docs/server2/intro_data_source.py
@@ -0,0 +1,37 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import re
+from path_utils import FormatKey
+from third_party.handlebar import Handlebar
+
+class IntroDataSource(object):
+ """This class fetches and loads JSON APIs with the fetcher passed in with
+ |cache_builder|, so the APIs can be plugged into templates.
+ """
+ def __init__(self, cache_builder, base_path):
+ self._cache = cache_builder.build(self._MakeIntroDict)
+ self._base_path = base_path
+
+ def _MakeIntroDict(self, intro):
+ headings = re.findall('<h([23]) id\="(.+)">(.+)</h[23]>', intro)
+ toc = []
+ for heading in headings:
+ level, link, title = heading
+ if level == '2':
+ toc.append({ 'link': link, 'title': title, 'subheadings': [] })
+ else:
+ toc[-1]['subheadings'].append({ 'link': link, 'title': title })
+ return { 'intro': Handlebar(intro), 'toc': toc }
+
+ def __getitem__(self, key):
+ return self.get(key)
+
+ def get(self, key):
+ real_path = FormatKey(key)
+ try:
+ return self._cache.get(self._base_path + '/' + real_path)
+ except:
+ pass
+ return None
« no previous file with comments | « chrome/common/extensions/docs/server2/echo_handler.py ('k') | chrome/common/extensions/docs/server2/path_utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698