| OLD | NEW |
| 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 copy | 5 import copy |
| 6 import logging | 6 import logging |
| 7 import os | 7 import os |
| 8 from collections import defaultdict, Mapping | 8 from collections import defaultdict, Mapping |
| 9 | 9 |
| 10 from branch_utility import BranchUtility | 10 from branch_utility import BranchUtility |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 def _GetLink(self, link): | 159 def _GetLink(self, link): |
| 160 if self._disable_refs: | 160 if self._disable_refs: |
| 161 type_name = link.split('.', 1)[-1] | 161 type_name = link.split('.', 1)[-1] |
| 162 return { 'href': '#type-%s' % type_name, 'text': link, 'name': link } | 162 return { 'href': '#type-%s' % type_name, 'text': link, 'name': link } |
| 163 return self._ref_resolver.SafeGetLink(link, namespace=self._namespace.name) | 163 return self._ref_resolver.SafeGetLink(link, namespace=self._namespace.name) |
| 164 | 164 |
| 165 def ToDict(self): | 165 def ToDict(self): |
| 166 if self._namespace is None: | 166 if self._namespace is None: |
| 167 return {} | 167 return {} |
| 168 return { | 168 as_dict = { |
| 169 'name': self._namespace.name, | 169 'name': self._namespace.name, |
| 170 'types': self._GenerateTypes(self._namespace.types.values()), | 170 'types': self._GenerateTypes(self._namespace.types.values()), |
| 171 'functions': self._GenerateFunctions(self._namespace.functions), | 171 'functions': self._GenerateFunctions(self._namespace.functions), |
| 172 'events': self._GenerateEvents(self._namespace.events), | 172 'events': self._GenerateEvents(self._namespace.events), |
| 173 'properties': self._GenerateProperties(self._namespace.properties), | 173 'properties': self._GenerateProperties(self._namespace.properties), |
| 174 'intro_list': self._GetIntroTableList(), | 174 'introList': self._GetIntroTableList(), |
| 175 'channel_warning': self._GetChannelWarning() | 175 'channelWarning': self._GetChannelWarning(), |
| 176 'byName': {}, |
| 176 } | 177 } |
| 178 # Make every type/function/event/property also accessible by name for |
| 179 # rendering specific API entities rather than the whole thing at once, for |
| 180 # example {{apis.manifestTypes.byName.ExternallyConnectable}}. |
| 181 for item_type in ('types', 'functions', 'events', 'properties'): |
| 182 as_dict['byName'].update( |
| 183 (item['name'], item) for item in as_dict[item_type]) |
| 184 return as_dict |
| 177 | 185 |
| 178 def _GetIntroTableList(self): | 186 def _GetIntroTableList(self): |
| 179 """Create a generic data structure that can be traversed by the templates | 187 """Create a generic data structure that can be traversed by the templates |
| 180 to create an API intro table. | 188 to create an API intro table. |
| 181 """ | 189 """ |
| 182 intro_rows = [ | 190 intro_rows = [ |
| 183 self._GetIntroDescriptionRow(), | 191 self._GetIntroDescriptionRow(), |
| 184 self._GetIntroAvailabilityRow() | 192 self._GetIntroAvailabilityRow() |
| 185 ] + self._GetIntroDependencyRows() | 193 ] + self._GetIntroDependencyRows() |
| 186 | 194 |
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 if self._disable_refs: | 679 if self._disable_refs: |
| 672 cache, ext = ( | 680 cache, ext = ( |
| 673 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else | 681 (self._idl_cache_no_refs, '.idl') if (unix_name in idl_names) else |
| 674 (self._json_cache_no_refs, '.json')) | 682 (self._json_cache_no_refs, '.json')) |
| 675 else: | 683 else: |
| 676 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else | 684 cache, ext = ((self._idl_cache, '.idl') if (unix_name in idl_names) else |
| 677 (self._json_cache, '.json')) | 685 (self._json_cache, '.json')) |
| 678 return self._GenerateHandlebarContext( | 686 return self._GenerateHandlebarContext( |
| 679 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), | 687 cache.GetFromFile('%s/%s%s' % (self._base_path, unix_name, ext)), |
| 680 path) | 688 path) |
| OLD | NEW |