Chromium Code Reviews| 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 classnames = defaultdict(list) | |
| 23 for property in self._properties.values(): | |
| 24 if property['api_class'] is not None: | |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
The indent level is getting a bit much here. Inver
aazzam
2016/12/13 05:01:09
done :)
| |
| 25 if property['api_class'] is True: | |
| 26 # This property had the generated_api_class flag set in CSSP roperties.in, | |
| 27 # but did not specify a class name. | |
| 28 classnames["CSSPropertyAPI" + property['upper_camel_name']]. append("CSSProperty" + property['upper_camel_name']) | |
| 29 elif isinstance(property['api_class'], str): | |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
Assert this condition, the else: case should never
aazzam
2016/12/13 05:01:09
done :)
| |
| 30 # This property has a specified class name. | |
| 31 classnames[property['api_class']].append("CSSProperty" + pro perty['upper_camel_name']) | |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
I think something like
classname = get_classname(a
| |
| 32 | |
| 33 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]) | |
| 34 self._api_classes = [] | |
| 35 | |
| 36 api_class = namedtuple('api_class', ('index', 'classname', 'propertyIDs' )) | |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
Use CamelCase for types.
I don't think a namedtup
aazzam
2016/12/13 05:01:09
The reason we thought of using a namedtuple instea
| |
| 37 for i, classname in enumerate(classnames.keys()): | |
| 38 self._api_classes.append(api_class(index=i + 1, classname=classname, propertyIDs=classnames[classname])) | |
|
alancutter (OOO until 2018)
2016/12/13 03:29:54
Use snake_case for propertyIDs.
aazzam
2016/12/13 05:01:09
done! :)
| |
| 39 | |
| 40 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') | |
| 41 def generate_property_descriptor_h(self): | |
| 42 return { | |
| 43 'api_classes': self._api_classes, | |
| 44 } | |
| 45 | |
| 46 if __name__ == '__main__': | |
| 47 in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv) | |
| OLD | NEW |