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

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

Issue 10832042: Extensions Docs Server: Doc conversion script (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: everything but svn stuff Created 8 years, 4 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 os 5 import os
6 6
7 def FormatKey(key): 7 def FormatKey(key):
8 """Normalize a key by making sure it has a .html extension, and convert any 8 """Normalize a key by making sure it has a .html extension, and convert any
9 '.'s to '_'s. 9 '.'s to '_'s.
10 """ 10 """
11 if key.endswith('.html'): 11 if key.endswith('.html'):
12 key = key[:-5] 12 key = key[:-5]
13 safe_key = key.replace('.', '_') 13 safe_key = key.replace('.', '_')
14 return safe_key + '.html' 14 return safe_key + '.html'
15 15
16 def SanitizeAPIName(name, api_path): 16 def SanitizeAPIName(name, api_path=''):
17 """Sanitizes API filenames that are in subdirectories. 17 """Sanitizes API filenames that are in subdirectories.
18 """ 18 """
19 filename = os.path.splitext(name)[0][len(api_path):].replace('/', '_') 19 filename = os.path.splitext(name)[0][len(api_path):].replace('/', '_')
20 if 'experimental' in filename: 20 if 'experimental' in filename:
21 filename = 'experimental_' + filename.replace('experimental_', '') 21 filename = 'experimental_' + filename.replace('experimental_', '')
22 return filename 22 return filename
23 23
24 def GetLinkToRefType(namespace_name, ref_type): 24 def GetLinkToRefType(namespace_name, ref_type):
25 """Returns a link given a $ref. 25 """Returns a link given a $ref.
26 """ 26 """
27 if ref_type.startswith(namespace_name + '.'): 27 if ref_type.startswith(namespace_name + '.'):
28 type_name = ref_type[len(namespace_name + '.'):] 28 type_name = ref_type[len(namespace_name + '.'):]
29 return { 'href': '#type-' + type_name, 'text': type_name } 29 return { 'href': '#type-' + type_name, 'text': type_name }
30 elif '.' not in ref_type: 30 elif '.' not in ref_type:
31 return { 'href': '#type-' + ref_type, 'text': ref_type } 31 return { 'href': '#type-' + ref_type, 'text': ref_type }
32 api, type_name = ref_type.rsplit('.', 1) 32 api, type_name = ref_type.rsplit('.', 1)
33 return { 'href': api + '.html#type-' + type_name, 'text': ref_type } 33 return { 'href': api + '.html#type-' + type_name, 'text': ref_type }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698