Index: chrome/common/extensions/docs/server2/handlebar_dict_generator.py |
diff --git a/chrome/common/extensions/docs/server2/handlebar_dict_generator.py b/chrome/common/extensions/docs/server2/handlebar_dict_generator.py |
index 456aa831bf2084e5e55c8ab15c0b292694b26406..7406ebfc706228aaa3c65440af9aeeda21e6ac94 100644 |
--- a/chrome/common/extensions/docs/server2/handlebar_dict_generator.py |
+++ b/chrome/common/extensions/docs/server2/handlebar_dict_generator.py |
@@ -22,17 +22,13 @@ def _RemoveNoDocs(item): |
return False |
def _GetLinkToRefType(namespace_name, ref_type): |
- terms = ref_type.split('.') |
- if len(terms) > 1: |
- text = '.'.join(terms[1:]) |
- href = terms[0] + '.html' + '#type-' + text |
- else: |
- href = namespace_name + '.html' + '#type-' +ref_type |
- text = ref_type |
- return ({ |
- "href": href, |
- "text": text |
- }) |
+ if ref_type.startswith(namespace_name + '.'): |
+ type_name = ref_type[namespace_name + '.':] |
not at google - send to devlin
2012/07/26 03:12:27
is this supposed to be len(namespace_name + '.') ?
cduvall
2012/07/26 17:57:44
Done.
|
+ return { 'href': '#type-' + type_name, 'text': type_name } |
+ elif '.' not in ref_type: |
+ return { 'href': '#type-' + ref_type, 'text': ref_type } |
+ api, type_name = ref_type.rsplit('.', 1) |
+ return { 'href': api + '.html#type-' + type_name, 'text': ref_type } |
def _FormatValue(value): |
"""Inserts commas every three digits for integer values. It is magic. |
@@ -52,6 +48,23 @@ class HandlebarDictGenerator(object): |
except Exception as e: |
logging.info(e) |
+ def _StripPrefix(self, name): |
+ if name.startswith(self._namespace.name + '.'): |
+ return name[len(self._namespace.name + '.'):] |
+ return name |
+ |
+ def _ReplaceRefsInDescription(self, description): |
not at google - send to devlin
2012/07/26 03:12:27
function needs -2 indentation
cduvall
2012/07/26 17:57:44
Done.
|
+ if description is None or '$ref:' not in description: |
+ return description |
+ refs = description.split('$ref:') |
not at google - send to devlin
2012/07/26 03:12:27
This is awesome. We should convert all those chrom
cduvall
2012/07/26 17:57:44
I shouldn't do this now because it will break the
not at google - send to devlin
2012/07/30 08:04:34
Actually it looks like it _does_ deal with $ref:
|
+ formatted_description = refs[0] |
+ for ref in refs[1:]: |
not at google - send to devlin
2012/07/26 03:12:27
I don't think this algorithm works if the descript
cduvall
2012/07/26 17:57:44
I think it does:
'$ref:Reffy is cool'.split('$ref
|
+ ref, rest = ref.split(' ', 1) |
+ ref_dict = _GetLinkToRefType(self._namespace.name, ref) |
+ formatted_description += ('<a href="' + ref_dict['href'] + '">' + |
+ ref_dict['text'] + '</a> ' + rest) |
not at google - send to devlin
2012/07/26 03:12:27
use a format string?
also, tip: += is inefficient
cduvall
2012/07/26 17:57:44
Done.
|
+ return formatted_description |
+ |
def Generate(self): |
try: |
return { |
@@ -66,7 +79,7 @@ class HandlebarDictGenerator(object): |
def _GenerateType(self, type_): |
type_dict = { |
- 'name': type_.name, |
+ 'name': self._StripPrefix(type_.name), |
'description': type_.description, |
not at google - send to devlin
2012/07/26 03:12:27
run *all* descriptions of through ReplaceRefsInDes
cduvall
2012/07/26 17:57:44
Done.
|
'properties': self._GenerateProperties(type_.properties), |
'functions': self._GenerateFunctions(type_.functions), |
@@ -98,7 +111,7 @@ class HandlebarDictGenerator(object): |
def _GenerateEvent(self, event): |
event_dict = { |
- 'name': event.name, |
+ 'name': self._StripPrefix(event.name), |
'description': event.description, |
'parameters': map(self._GenerateProperty, event.params) |
} |
@@ -127,9 +140,9 @@ class HandlebarDictGenerator(object): |
def _GenerateProperty(self, property_): |
property_dict = { |
- 'name': property_.name, |
+ 'name': self._StripPrefix(property_.name), |
'optional': property_.optional, |
- 'description': property_.description, |
+ 'description': self._ReplaceRefsInDescription(property_.description), |
'properties': self._GenerateProperties(property_.properties), |
'functions': self._GenerateFunctions(property_.functions) |
} |