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

Side by Side Diff: chrome/common/extensions/docs/server2/intro_data_source.py

Issue 10815042: Extensions Docs Server: api_index.html, experimental.html (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 re 5 import re
6 from path_utils import FormatKey 6 from path_utils import FormatKey
7 from third_party.handlebar import Handlebar 7 from third_party.handlebar import Handlebar
8 8
9 class IntroDataSource(object): 9 class IntroDataSource(object):
10 """This class fetches the intros for a given API. From this intro, a table 10 """This class fetches the intros for a given API. From this intro, a table
11 of contents dictionary is created, which contains the headings in the intro. 11 of contents dictionary is created, which contains the headings in the intro.
12 """ 12 """
13 def __init__(self, cache_builder, base_paths): 13 def __init__(self, cache_builder, base_paths):
14 self._cache = cache_builder.build(self._MakeIntroDict) 14 self._cache = cache_builder.build(self._MakeIntroDict)
15 self._base_paths = base_paths 15 self._base_paths = base_paths
16 16
17 def _MakeIntroDict(self, intro): 17 def _MakeIntroDict(self, intro):
18 h1s = re.findall('<h1.*>(.+)</h1>', intro) 18 h1s = re.findall('<h1.*>(.+)</h1>', intro)
19 if len(h1s) > 0: 19 if len(h1s) > 0:
20 page_title = h1s[0] 20 page_title = h1s[0]
21 intro = re.sub('<h1.*>(.+)</h1>', '', intro, 1)
cduvall 2012/07/20 21:51:29 Remove the h1 from the file because it is put in l
not at google - send to devlin 2012/07/23 12:40:24 If it's here anyway why remove it? If we do for s
cduvall 2012/07/23 20:38:19 I did this so in the template, the title could go
not at google - send to devlin 2012/07/23 23:37:43 Ah I see. Is it not enough for the TOC to go over
21 else: 22 else:
22 page_title = '' 23 page_title = ''
23 headings = re.findall('<h([23]) id\="(.+)">(.+)</h[23]>', intro) 24 headings = re.findall('<h([23]) id\="(.+)">(.+)</h[23]>', intro)
24 toc = [] 25 toc = []
25 for heading in headings: 26 for heading in headings:
26 level, link, title = heading 27 level, link, title = heading
27 if level == '2': 28 if level == '2':
28 toc.append({ 'link': link, 'title': title, 'subheadings': [] }) 29 toc.append({ 'link': link, 'title': title, 'subheadings': [] })
29 else: 30 else:
30 toc[-1]['subheadings'].append({ 'link': link, 'title': title }) 31 toc[-1]['subheadings'].append({ 'link': link, 'title': title })
31 return { 'intro': Handlebar(intro), 'toc': toc , 'title': page_title } 32 return { 'intro': Handlebar(intro), 'toc': toc , 'title': page_title }
32 33
33 def __getitem__(self, key): 34 def __getitem__(self, key):
34 return self.get(key) 35 return self.get(key)
35 36
36 def get(self, key): 37 def get(self, key):
37 real_path = FormatKey(key) 38 real_path = FormatKey(key)
38 for base_path in self._base_paths: 39 for base_path in self._base_paths:
39 try: 40 try:
40 return self._cache.GetFromFile(base_path + '/' + real_path) 41 return self._cache.GetFromFile(base_path + '/' + real_path)
41 except Exception: 42 except Exception:
42 pass 43 pass
43 return None 44 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698