| 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 7f3d32cce0ad568421460759885c0cf3581089d8..e340c0f1974be69b743136715d7dbb6c89b1fd2e 100644
|
| --- a/chrome/common/extensions/docs/server2/api_data_source.py
|
| +++ b/chrome/common/extensions/docs/server2/api_data_source.py
|
| @@ -2,11 +2,14 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +import collections
|
| import copy
|
| +import json as json_library
|
| import logging
|
| import os
|
| from collections import defaultdict, Mapping
|
|
|
| +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 +106,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,12 +144,52 @@ class _JSCModel(object):
|
| return {}
|
| return {
|
| 'name': self._namespace.name,
|
| + 'description': self._namespace.description,
|
| + 'availability': self._GetApiAvailability(),
|
| + 'experimental': self._CheckExperimental(),
|
| + 'api_permissions': self._GetPermissions(),
|
| + 'learn_more': self._GetMoreLearning(),
|
| '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)
|
| }
|
|
|
| + def _GetApiAvailability(self):
|
| + """Finds the earliest stable version of chrome where an API was available
|
| + using AvailabilityFinder. If an API hasn't been released to stable yet,
|
| + then the development channel that the API is currently available on will
|
| + be returned instead.
|
| + """
|
| + if not self._CheckExperimental():
|
| + availability = self._availability_finder.GetApiAvailability(
|
| + self._namespace.name)
|
| + if availability:
|
| + if availability.channel == 'stable':
|
| + return availability.version
|
| + return availability.channel
|
| + # A special message for experimental APIs' availability will be displayed.
|
| + return None
|
| +
|
| + def _CheckExperimental(self):
|
| + return self._namespace.name.startswith('experimental')
|
| +
|
| + def _GetPermissions(self):
|
| + """This is a temporary fix for generating API intro tables automatically.
|
| + Information on an API's permissions is pulled from a json file so that it
|
| + can be sent to the templates along with other relevant intro data.
|
| + """
|
| + table_info = self._intro_tables.get(self._namespace.name)
|
| + return table_info.get('Permissions') if table_info else None
|
| +
|
| + def _GetMoreLearning(self):
|
| + """We can't automatically generate the "Learn more" field in an API's.
|
| + intro table; instead, we pull it from a json file so that it can be sent to
|
| + the templates along with other relevant intro data.
|
| + """
|
| + table_info = self._intro_tables.get(self._namespace.name)
|
| + return table_info.get('LearnMore') if table_info else None
|
| +
|
| def _GenerateTypes(self, types):
|
| return [self._GenerateType(t) for t in types]
|
|
|
| @@ -324,7 +376,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)
|
|
|
| @@ -352,7 +407,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
|
| @@ -398,7 +456,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)
|
| @@ -406,6 +466,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):
|
| @@ -483,10 +545,18 @@ 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 _DetermineNamesForGet(self, key):
|
| + return (path, unix_name)
|
| +
|
| + def _DetermineCacheForGet(self, unix_name):
|
| + return (cache, ext)
|
| +
|
| def get(self, key):
|
| if key.endswith('.html') or key.endswith('.json') or key.endswith('.idl'):
|
| path, ext = os.path.splitext(key)
|
|
|