OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 import json5_generator | |
7 import template_expander | |
8 import make_style_builder | |
9 | |
10 from name_utilities import enum_for_css_keyword, enum_value_name | |
11 | |
12 | |
13 class CSSValueIDMappingsWriter(make_style_builder.StyleBuilderWriter): | |
14 def __init__(self, json5_file_path): | |
15 super(CSSValueIDMappingsWriter, self).__init__(json5_file_path) | |
16 self._outputs = { | |
17 'CSSValueIDMappingsGenerated.h': self.generate_css_value_mappings, | |
18 } | |
19 | |
20 @template_expander.use_jinja('CSSValueIDMappingsGenerated.h.tmpl') | |
21 def generate_css_value_mappings(self): | |
22 mappings = {} | |
23 include_paths = [] | |
24 for property_ in self._properties.values(): | |
25 if property_['field_template'] == 'keyword': | |
26 if property_['field_type_path']: | |
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 | |
32 mappings[type_name] = { | |
33 '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']], | |
35 } | |
36 | |
37 return { | |
38 'include_paths': list(sorted(include_paths)), | |
39 'mappings': mappings, | |
40 } | |
41 | |
42 if __name__ == '__main__': | |
43 json5_generator.Maker(CSSValueIDMappingsWriter).main() | |
OLD | NEW |