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

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

Issue 99703004: Docserver: Fix the TOC rendering for API references by fixing the haphazard way (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 from extensions_paths import PRIVATE_TEMPLATES 5 from extensions_paths import PRIVATE_TEMPLATES
6 from file_system import FileNotFoundError 6 from file_system import FileNotFoundError
7 7
8 8
9 class TableOfContentsRenderer(object): 9 class TableOfContentsRenderer(object):
10 '''Renders a table of contents pulled from a list of DocumentSections 10 '''Renders a table of contents pulled from a list of DocumentSections
(...skipping 15 matching lines...) Expand all
26 (text, warnings). 26 (text, warnings).
27 ''' 27 '''
28 path = '%s/table_of_contents.html' % PRIVATE_TEMPLATES 28 path = '%s/table_of_contents.html' % PRIVATE_TEMPLATES
29 try: 29 try:
30 table_of_contents_template = self._templates.GetFromFile(path).Get() 30 table_of_contents_template = self._templates.GetFromFile(path).Get()
31 except FileNotFoundError: 31 except FileNotFoundError:
32 return '', ['%s not found' % path] 32 return '', ['%s not found' % path]
33 33
34 def make_toc_items(entries): 34 def make_toc_items(entries):
35 return [{ 35 return [{
36 'attributes': [(key, val) for key, val in entry.attributes.iteritems() 36 'attributes': [{'key': key, 'value': val}
37 for key, val in entry.attributes.iteritems()
37 if key != 'id'], 38 if key != 'id'],
38 'link': entry.attributes.get('id', ''), 39 'link': entry.attributes.get('id', ''),
39 'subheadings': make_toc_items(entry.entries), 40 'subheadings': make_toc_items(entry.entries),
40 'title': entry.name, 41 'title': entry.name,
41 } for entry in entries] 42 } for entry in entries]
42 43
43 toc_items = [] 44 toc_items = []
44 for section in sections: 45 for section in sections:
45 items_for_section = make_toc_items(section.structure) 46 items_for_section = make_toc_items(section.structure)
46 if toc_items and items_for_section: 47 if toc_items and items_for_section:
47 items_for_section[0]['separator'] = True 48 items_for_section[0]['separator'] = True
48 toc_items.extend(items_for_section) 49 toc_items.extend(items_for_section)
49 50
50 return self._template_renderer.Render( 51 return self._template_renderer.Render(
51 self._templates.GetFromFile( 52 self._templates.GetFromFile(
52 '%s/table_of_contents.html' % PRIVATE_TEMPLATES).Get(), 53 '%s/table_of_contents.html' % PRIVATE_TEMPLATES).Get(),
53 None, # no request 54 None, # no request
54 data_sources=('partials'), 55 data_sources=('partials'),
55 additional_context={'items': toc_items}) 56 additional_context={'items': toc_items})
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/known_broken_links.json ('k') | chrome/common/extensions/docs/static/css/site.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698