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

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

Issue 10577022: Extensions Docs Server: HandlebarDictGenerator (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor changes Created 8 years, 6 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
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 json 5 import json
6 import os 6 import os
7 7
8 from handlebar_dict_generator import HandlebarDictGenerator
8 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater 9 import third_party.json_schema_compiler.json_comment_eater as json_comment_eater
9 import third_party.json_schema_compiler.model as model 10 import third_party.json_schema_compiler.model as model
10 11
11 class APIDataSource(object): 12 class APIDataSource(object):
12 """This class fetches and loads JSON APIs with the fetcher passed in with 13 """This class fetches and loads JSON APIs with the fetcher passed in with
13 |cache_builder|, so the APIs can be plugged into templates. 14 |cache_builder|, so the APIs can be plugged into templates.
14 """ 15 """
15 def __init__(self, cache_builder, base_paths): 16 def __init__(self, cache_builder, base_paths):
16 self._cache = cache_builder.build(self._LoadAPI) 17 self._cache = cache_builder.build(self._LoadAPI)
17 self._base_paths = base_paths 18 self._base_paths = base_paths
18 19
19 def _LoadAPI(self, api): 20 def _LoadAPI(self, api):
20 return json.loads(json_comment_eater.Nom(api))[0] 21 generator = HandlebarDictGenerator(
22 json.loads(json_comment_eater.Nom(api))[0])
23 return generator.Generate()
21 24
22 def __getitem__(self, key): 25 def __getitem__(self, key):
23 return self.get(key) 26 return self.get(key)
24 27
25 def get(self, key): 28 def get(self, key):
26 path, ext = os.path.splitext(key) 29 path, ext = os.path.splitext(key)
27 unix_name = model.UnixName(path) 30 unix_name = model.UnixName(path)
28 json_path = unix_name + '.json' 31 json_path = unix_name + '.json'
29 for base_path in self._base_paths: 32 for base_path in self._base_paths:
30 try: 33 try:
31 return self._cache.get(base_path + '/' + json_path) 34 return self._cache.get(base_path + '/' + json_path)
32 except: 35 except:
33 pass 36 pass
34 return None 37 return None
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/server2/api_data_source_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698