OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 import json5_generator | 6 import json5_generator |
7 import template_expander | 7 import template_expander |
8 import make_style_builder | 8 import make_style_builder |
9 | 9 |
10 from name_utilities import enum_for_css_keyword, enum_value_name | 10 from name_utilities import enum_for_css_keyword, enum_value_name |
11 | 11 |
12 | 12 |
13 class CSSValueIDMappingsWriter(make_style_builder.StyleBuilderWriter): | 13 class CSSValueIDMappingsWriter(make_style_builder.StyleBuilderWriter): |
14 def __init__(self, json5_file_path): | 14 def __init__(self, json5_file_path): |
15 super(CSSValueIDMappingsWriter, self).__init__(json5_file_path) | 15 super(CSSValueIDMappingsWriter, self).__init__(json5_file_path) |
16 self._outputs = { | 16 self._outputs = { |
17 'CSSValueIDMappingsGenerated.h': self.generate_css_value_mappings, | 17 'CSSValueIDMappingsGenerated.h': self.generate_css_value_mappings, |
18 } | 18 } |
19 | 19 |
20 @template_expander.use_jinja('CSSValueIDMappingsGenerated.h.tmpl') | 20 @template_expander.use_jinja('CSSValueIDMappingsGenerated.h.tmpl') |
21 def generate_css_value_mappings(self): | 21 def generate_css_value_mappings(self): |
22 mappings = {} | 22 mappings = {} |
23 include_paths = [] | 23 include_paths = set() |
24 for property_ in self._properties.values(): | 24 for property_ in self._properties.values(): |
25 if property_['field_template'] == 'keyword': | 25 if property_['field_template'] == 'keyword': |
26 if property_['field_type_path']: | 26 include_paths.update(property_['include_paths']) |
27 type_name = property_['field_type_path'].split('/')[-1] | |
28 include_paths.append(property_['field_type_path'] + '.h') | |
29 else: | |
30 type_name = property_['type_name'] | |
31 | 27 |
32 mappings[type_name] = { | 28 mappings[property_['type_name']] = { |
33 'default_value': enum_value_name(property_['default_value'])
, | 29 'default_value': enum_value_name(property_['default_value'])
, |
34 'mapping': [(enum_value_name(k), enum_for_css_keyword(k)) fo
r k in property_['keywords']], | 30 'mapping': [(enum_value_name(k), enum_for_css_keyword(k)) fo
r k in property_['keywords']], |
35 } | 31 } |
36 | 32 |
37 return { | 33 return { |
38 'include_paths': list(sorted(include_paths)), | 34 'include_paths': list(sorted(include_paths)), |
39 'mappings': mappings, | 35 'mappings': mappings, |
40 } | 36 } |
41 | 37 |
42 if __name__ == '__main__': | 38 if __name__ == '__main__': |
43 json5_generator.Maker(CSSValueIDMappingsWriter).main() | 39 json5_generator.Maker(CSSValueIDMappingsWriter).main() |
OLD | NEW |