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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 import re
6 from path_utils import FormatKey
7 from third_party.handlebar import Handlebar
8
9 class IntroDataSource(object):
10 """This class fetches and loads JSON APIs with the fetcher passed in with
11 |cache_builder|, so the APIs can be plugged into templates.
12 """
13 def __init__(self, cache_builder, base_path):
14 self._cache = cache_builder.build(self._MakeIntroDict)
15 self._base_path = base_path
16
17 def _MakeIntroDict(self, intro):
18 headings = re.findall('<h([23]) id\="(.+)">(.+)</h[23]>', intro)
19 toc = []
20 for heading in headings:
21 level, link, title = heading
22 if level == '2':
23 toc.append({ 'link': link, 'title': title, 'subheadings': [] })
24 else:
25 toc[-1]['subheadings'].append({ 'link': link, 'title': title })
26 return { 'intro': Handlebar(intro), 'toc': toc }
27
28 def __getitem__(self, key):
29 return self.get(key)
30
31 def get(self, key):
32 real_path = FormatKey(key)
33 try:
34 return self._cache.get(self._base_path + '/' + real_path)
35 except:
36 pass
37 return None
OLDNEW
« 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