OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2016 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 import sys | |
7 | |
8 import in_generator | |
9 import template_expander | |
10 import make_style_builder | |
11 from collections import namedtuple, defaultdict | |
12 | |
13 | |
14 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): | |
15 def __init__(self, in_file_path): | |
16 super(CSSPropertyAPIWriter, self).__init__(in_file_path) | |
17 self._outputs = { | |
18 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_h, | |
19 } | |
20 | |
21 # Temporary map of classname to list of propertyIDs. | |
22 properties_for_class = defaultdict(list) | |
23 for property in self._properties.values(): | |
24 if property['api_class'] is None: | |
25 continue | |
26 classname = self.get_classname(property) | |
27 properties_for_class[classname].append('CSSProperty' + property['upp er_camel_name']) | |
alancutter (OOO until 2018)
2016/12/13 05:55:34
Use property['property_id'] instead of constructin
aazzam
2016/12/13 21:47:52
done :)
| |
28 | |
29 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]). | |
30 self._api_classes = [] | |
31 | |
32 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') ) | |
33 for i, classname in enumerate(properties_for_class.keys()): | |
34 self._api_classes.append(ApiClass(index=i + 1, classname=classname, property_ids=properties_for_class[classname])) | |
35 | |
36 # Gets the classname for a given property. | |
37 def get_classname(self, property): | |
38 if property['api_class'] is True: | |
39 # This property had the generated_api_class flag set in CSSPropertie s.in. | |
40 return 'CSSPropertyAPI' + property['upper_camel_name'] | |
41 else: | |
alancutter (OOO until 2018)
2016/12/13 05:55:34
No need for else after return.
aazzam
2016/12/13 21:47:52
done :)
| |
42 # This property has a specified class name. | |
43 assert isinstance(property['api_class'], str) | |
44 return property['api_class'] | |
45 | |
46 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') | |
47 def generate_property_descriptor_h(self): | |
48 return { | |
49 'api_classes': self._api_classes, | |
50 } | |
51 | |
52 if __name__ == '__main__': | |
53 in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv) | |
OLD | NEW |