| 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 = set() | 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'] in ('keyword', 'multi_keyword'): |
| 26 include_paths.update(property_['include_paths']) | 26 include_paths.update(property_['include_paths']) |
| 27 | 27 |
| 28 mappings[property_['type_name']] = { | 28 mappings[property_['type_name']] = { |
| 29 'default_value': enum_value_name(property_['default_value'])
, | 29 'default_value': enum_value_name(property_['default_value'])
, |
| 30 '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']], |
| 31 } | 31 } |
| 32 | 32 |
| 33 return { | 33 return { |
| 34 'include_paths': list(sorted(include_paths)), | 34 'include_paths': list(sorted(include_paths)), |
| 35 'mappings': mappings, | 35 'mappings': mappings, |
| 36 } | 36 } |
| 37 | 37 |
| 38 if __name__ == '__main__': | 38 if __name__ == '__main__': |
| 39 json5_generator.Maker(CSSValueIDMappingsWriter).main() | 39 json5_generator.Maker(CSSValueIDMappingsWriter).main() |
| OLD | NEW |