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

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

Issue 18323018: Linking AvailabilityFinder with APIDataSource and intro-table templates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More Generic Templates Created 7 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 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 3fdd37587de23c6e4c8eab94d7958da966880ae4..52b491e3f1ebd1150897785bedeed5948531e984 100644
--- a/chrome/common/extensions/docs/server2/api_data_source.py
+++ b/chrome/common/extensions/docs/server2/api_data_source.py
@@ -7,6 +7,8 @@ import logging
import os
from collections import defaultdict, Mapping
+from branch_utility import BranchUtility
+import svn_constants
import third_party.json_schema_compiler.json_parse as json_parse
import third_party.json_schema_compiler.model as model
import third_party.json_schema_compiler.idl_schema as idl_schema
@@ -103,9 +105,18 @@ class _JSCModel(object):
"""Uses a Model from the JSON Schema Compiler and generates a dict that
a Handlebar template can use for a data source.
"""
- def __init__(self, json, ref_resolver, disable_refs, idl=False):
+ def __init__(self,
+ json,
+ ref_resolver,
+ disable_refs,
+ availability_finder,
+ intro_cache,
+ idl=False):
self._ref_resolver = ref_resolver
self._disable_refs = disable_refs
+ self._availability_finder = availability_finder
+ self._intro_tables = intro_cache.GetFromFile(
+ '%s/intro_tables.json' % svn_constants.JSON_PATH)
clean_json = copy.deepcopy(json)
if _RemoveNoDocs(clean_json):
self._namespace = None
@@ -132,13 +143,66 @@ class _JSCModel(object):
return {}
return {
'name': self._namespace.name,
- 'description': self._namespace.description,
'types': self._GenerateTypes(self._namespace.types.values()),
'functions': self._GenerateFunctions(self._namespace.functions),
'events': self._GenerateEvents(self._namespace.events),
- 'properties': self._GenerateProperties(self._namespace.properties)
+ 'properties': self._GenerateProperties(self._namespace.properties),
+ 'intro_list': self._GetIntroTableList()
}
+ def _GetIntroTableList(self):
+ """Create a generic data structure that can be traversed by the templates
+ to create an API intro table.
+ """
+ intro_list = []
+ intro_list.append({
+ 'title': 'Description',
+ 'content': [
+ { 'text': self._FormatDescription(self._namespace.description) }
+ ]
+ })
not at google - send to devlin 2013/07/16 22:25:00 more concise: intro_list = [{ 'title': 'Descrip
epeterson 2013/07/17 23:48:23 Done.
+
+ availability = None
+ if self._IsExperimental():
+ status = 'experimental'
+ else:
+ availability = self._GetApiAvailability()
+ status = availability.channel
+ intro_list.append({
+ 'title': 'Availability',
+ 'content': [
+ {
+ 'message': True,
+ status: True,
+ 'version': availability.version if status == 'stable' else None
not at google - send to devlin 2013/07/16 22:25:00 maybe hold onto version rather than availability,
epeterson 2013/07/17 23:48:23 Done.
+ }
epeterson 2013/07/16 00:28:23 I tried a lot of different things here. I couldn'
not at google - send to devlin 2013/07/16 22:25:00 I think you could combine message and status into
epeterson 2013/07/17 23:48:23 Done. But I had to add in extra logic to pass in a
+ ]
+ })
+
+ # Look up the API name in intro_tables.json, which is structured similarly
+ # to the data structure being created. If the name is found, loop through
+ # the attributes and add them to this structure.
+ table_info = self._intro_tables.get(self._namespace.name)
+ if table_info is None:
+ return intro_list
+
+ # The intro tables have a specific ordering that needs to be followed.
+ ordering = ('Permissions', 'Samples', 'Learn More')
+
+ for category in ordering:
+ if category in table_info.keys():
+ intro_list.append({
+ 'title': category,
+ 'content': table_info.get(category, [])
+ })
+ return intro_list
+
+ def _GetApiAvailability(self):
+ return self._availability_finder.GetApiAvailability(self._namespace.name)
+
+ def _IsExperimental(self):
+ return self._namespace.name.startswith('experimental')
+
def _GenerateTypes(self, types):
return [self._GenerateType(t) for t in types]
@@ -325,7 +389,10 @@ class APIDataSource(object):
|compiled_fs_factory|, so the APIs can be plugged into templates.
"""
class Factory(object):
- def __init__(self, compiled_fs_factory, base_path):
+ def __init__(self,
+ compiled_fs_factory,
+ base_path,
+ availability_finder_factory):
def create_compiled_fs(fn, category):
return compiled_fs_factory.Create(fn, APIDataSource, category=category)
@@ -353,7 +420,10 @@ class APIDataSource(object):
self._names_cache = create_compiled_fs(self._GetAllNames, 'names')
self._base_path = base_path
-
+ self._availability_finder = availability_finder_factory.Create()
+ self._intro_cache = create_compiled_fs(
+ lambda _, json: json_parse.Parse(json),
+ 'intro-cache')
# These must be set later via the SetFooDataSourceFactory methods.
self._ref_resolver_factory = None
self._samples_data_source_factory = None
@@ -399,7 +469,9 @@ class APIDataSource(object):
return _JSCModel(
json_parse.Parse(api)[0],
self._ref_resolver_factory.Create() if not disable_refs else None,
- disable_refs).ToDict()
+ disable_refs,
+ self._availability_finder,
+ self._intro_cache).ToDict()
def _LoadIdlAPI(self, api, disable_refs):
idl = idl_parser.IDLParser().ParseData(api)
@@ -407,6 +479,8 @@ class APIDataSource(object):
idl_schema.IDLSchema(idl).process()[0],
self._ref_resolver_factory.Create() if not disable_refs else None,
disable_refs,
+ self._availability_finder,
+ self._intro_cache,
idl=True).ToDict()
def _GetIDLNames(self, base_dir, apis):
@@ -484,8 +558,10 @@ class APIDataSource(object):
def _GetAsSubdirectory(self, name):
if name.startswith('experimental_'):
parts = name[len('experimental_'):].split('_', 1)
- parts[1] = 'experimental_%s' % parts[1]
- return '/'.join(parts)
+ if len(parts) > 1:
+ parts[1] = 'experimental_%s' % parts[1]
+ return '/'.join(parts)
+ return '%s/%s' % (parts[0], name)
return name.replace('_', '/', 1)
def get(self, key):

Powered by Google App Engine
This is Rietveld 408576698