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 | |
| 12 from collections import namedtuple, defaultdict | |
| 13 | |
| 14 | |
| 15 # Gets the classname for a given property. | |
| 16 def get_classname(property): | |
| 17 if property['api_class'] is True: | |
| 18 # This property had the generated_api_class flag set in CSSProperties.in . | |
| 19 return 'CSSPropertyAPI' + property['upper_camel_name'] | |
| 20 # This property has a specified class name. | |
| 21 assert isinstance(property['api_class'], str), \ | |
| 22 ("api_class value for " + property['api_class'] + " should be None, True or a string") | |
| 23 return property['api_class'] | |
| 24 | |
| 25 | |
| 26 class CSSPropertyAPIWriter(make_style_builder.StyleBuilderWriter): | |
| 27 def __init__(self, in_file_path): | |
| 28 super(CSSPropertyAPIWriter, self).__init__(in_file_path) | |
| 29 self._outputs = { | |
| 30 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, | |
| 31 } | |
| 32 | |
| 33 # Temporary map of API classname to list of propertyIDs that the API cla ss is for. | |
| 34 properties_for_class = defaultdict(list) | |
| 35 for property in self._properties.values(): | |
| 36 if property['api_class'] is None: | |
| 37 continue | |
| 38 classname = get_classname(property) | |
| 39 properties_for_class[classname].append(property['property_id']) | |
| 40 | |
| 41 # Stores a list of classes with elements (index, classname, [propertyIDs , ..]). | |
| 42 self._api_classes = [] | |
| 43 | |
| 44 ApiClass = namedtuple('ApiClass', ('index', 'classname', 'property_ids') ) | |
| 45 for i, classname in enumerate(properties_for_class.keys()): | |
| 46 self._api_classes.append(ApiClass(index=i + 1, classname=classname, property_ids=properties_for_class[classname])) | |
|
sashab
2016/12/13 23:32:32
You can reformat this to be a little easier to rea
aazzam
2016/12/13 23:36:06
looks much nicer :)
| |
| 47 | |
| 48 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') | |
| 49 def generate_property_descriptor_cpp(self): | |
| 50 return { | |
| 51 'api_classes': self._api_classes, | |
| 52 } | |
| 53 | |
| 54 if __name__ == '__main__': | |
| 55 in_generator.Maker(CSSPropertyAPIWriter).main(sys.argv) | |
| OLD | NEW |