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

Unified Diff: chrome/common/extensions/docs/server2/api_data_source.py

Issue 14322003: Inline docs render properly in extensions doc server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/common/extensions/docs/server2/api_data_source.py
diff --git a/chrome/common/extensions/docs/server2/api_data_source.py b/chrome/common/extensions/docs/server2/api_data_source.py
index 70d52e71e580439a69b160a420dfbc4e5e0566eb..d7e965cbcc67c987d00567b03a4d4b1637ade8ed 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -5,6 +5,7 @@
import copy
import logging
import os
+import collections
from file_system import FileNotFoundError
import third_party.json_schema_compiler.json_parse as json_parse
@@ -14,7 +15,7 @@ import third_party.json_schema_compiler.idl_parser as idl_parser
# Increment this if the data model changes for APIDataSource.
# This would include changes to model.py in json_schema_compiler!
-_VERSION = 17
+_VERSION = 18
def _RemoveNoDocs(item):
if json_parse.IsDict(item):
@@ -35,6 +36,46 @@ def _RemoveNoDocs(item):
item.remove(i)
return False
+
+def _InlineDocs(schema):
+ """ Replace '$ref's that refer to inline_docs with the json for those docs
cduvall 2013/04/18 00:02:41 no space after """
+ """
+ # Gather the types with inline_doc.
+ types = schema.get('types')
+
+ if types is None:
+ return
+
+ inline_docs = {}
+ types_without_inline_doc = []
+
+ for type_ in types:
+ if type_.get('inline_doc'):
+ inline_docs[type_['id']] = type_
+ del type_['inline_doc']
+ del type_['id']
+ else:
+ types_without_inline_doc.append(type_)
+
+ schema['types'] = types_without_inline_doc
+
+ def apply_inline(node):
+ ref = node.get('$ref')
+
+ if ref and ref in inline_docs:
+ node.update(inline_docs[ref])
+ del node['$ref']
+
+ for k, v in node.iteritems():
+ if isinstance(v, collections.Mapping):
+ apply_inline(v)
+ elif isinstance(v, list):
+ for i in v:
+ if isinstance(i, collections.Mapping):
+ apply_inline(i)
+
+ apply_inline(schema)
+
def _CreateId(node, prefix):
if node.parent is not None and not isinstance(node.parent, model.Namespace):
return '-'.join([prefix, node.parent.simple_name, node.simple_name])
@@ -57,6 +98,7 @@ class _JSCModel(object):
if _RemoveNoDocs(clean_json):
self._namespace = None
else:
+ _InlineDocs(clean_json)
self._namespace = model.Namespace(clean_json, clean_json['namespace'])
def _FormatDescription(self, description):

Powered by Google App Engine
This is Rietveld 408576698