| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 sys | 6 import sys |
| 7 | 7 |
| 8 import json5_generator | 8 import json5_generator |
| 9 import template_expander | 9 import template_expander |
| 10 import make_style_builder | 10 import make_style_builder |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 def __init__(self, json5_file_paths): | 37 def __init__(self, json5_file_paths): |
| 38 super(CSSPropertyAPIWriter, self).__init__(json5_file_paths[0]) | 38 super(CSSPropertyAPIWriter, self).__init__(json5_file_paths[0]) |
| 39 # TODO(aazzam): Move the logic for loading CSSPropertyAPIMethods.json5 i
nto a new class APIMethodsWriter(). | 39 # TODO(aazzam): Move the logic for loading CSSPropertyAPIMethods.json5 i
nto a new class APIMethodsWriter(). |
| 40 assert len(json5_file_paths) == 2,\ | 40 assert len(json5_file_paths) == 2,\ |
| 41 'CSSPropertyAPIWriter requires 2 input json5 files files, got {}.'.f
ormat(len(json5_file_paths)) | 41 'CSSPropertyAPIWriter requires 2 input json5 files files, got {}.'.f
ormat(len(json5_file_paths)) |
| 42 | 42 |
| 43 self.css_property_api_methods = Json5File.load_from_files([json5_file_pa
ths[1]], {}, {}) | 43 self.css_property_api_methods = Json5File.load_from_files([json5_file_pa
ths[1]], {}, {}) |
| 44 | 44 |
| 45 self._outputs = { | 45 self._outputs = { |
| 46 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, | 46 'CSSPropertyDescriptor.cpp': self.generate_property_descriptor_cpp, |
| 47 'CSSPropertyDescriptor.h': self.generate_property_descriptor_h, |
| 47 'CSSPropertyAPI.h': self.generate_property_api, | 48 'CSSPropertyAPI.h': self.generate_property_api, |
| 48 } | 49 } |
| 49 | 50 |
| 50 # Stores a map of API method name -> (return_type, parameters) | 51 # Stores a map of API method name -> (return_type, parameters) |
| 51 self.all_api_methods = {} | 52 self.all_api_methods = {} |
| 52 # Stores an ordered list of all API method names. This must match the | 53 # Stores an ordered list of all API method names. This must match the |
| 53 # order they appear in the Descriptor object. | 54 # order they appear in the Descriptor object. |
| 54 self.ordered_api_method_names = [] | 55 self.ordered_api_method_names = [] |
| 55 for api_method in self.css_property_api_methods.name_dictionaries: | 56 for api_method in self.css_property_api_methods.name_dictionaries: |
| 56 self.ordered_api_method_names.append(api_method['name']) | 57 self.ordered_api_method_names.append(api_method['name']) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 86 methods_for_class=self.methods_for_classes[classname] | 87 methods_for_class=self.methods_for_classes[classname] |
| 87 )) | 88 )) |
| 88 | 89 |
| 89 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') | 90 @template_expander.use_jinja('CSSPropertyDescriptor.cpp.tmpl') |
| 90 def generate_property_descriptor_cpp(self): | 91 def generate_property_descriptor_cpp(self): |
| 91 return { | 92 return { |
| 92 'api_classes': self._api_classes, | 93 'api_classes': self._api_classes, |
| 93 'ordered_api_method_names': self.ordered_api_method_names, | 94 'ordered_api_method_names': self.ordered_api_method_names, |
| 94 } | 95 } |
| 95 | 96 |
| 97 @template_expander.use_jinja('CSSPropertyDescriptor.h.tmpl') |
| 98 def generate_property_descriptor_h(self): |
| 99 return { |
| 100 'ordered_api_method_names': self.ordered_api_method_names, |
| 101 'all_api_methods': self.all_api_methods, |
| 102 } |
| 103 |
| 96 @template_expander.use_jinja('CSSPropertyAPI.h.tmpl') | 104 @template_expander.use_jinja('CSSPropertyAPI.h.tmpl') |
| 97 def generate_property_api(self): | 105 def generate_property_api(self): |
| 98 return { | 106 return { |
| 99 'ordered_api_method_names': self.ordered_api_method_names, | 107 'ordered_api_method_names': self.ordered_api_method_names, |
| 100 'all_api_methods': self.all_api_methods, | 108 'all_api_methods': self.all_api_methods, |
| 101 } | 109 } |
| 102 | 110 |
| 103 # Provides a function object given the classname of the property. | 111 # Provides a function object given the classname of the property. |
| 104 def generate_property_api_h_builder(self, api_classname): | 112 def generate_property_api_h_builder(self, api_classname): |
| 105 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') | 113 @template_expander.use_jinja('CSSPropertyAPIFiles.h.tmpl') |
| 106 def generate_property_api_h(): | 114 def generate_property_api_h(): |
| 107 return { | 115 return { |
| 108 'api_classname': api_classname, | 116 'api_classname': api_classname, |
| 109 'methods_for_class': self.methods_for_classes[api_classname], | 117 'methods_for_class': self.methods_for_classes[api_classname], |
| 110 'all_api_methods': self.all_api_methods, | 118 'all_api_methods': self.all_api_methods, |
| 111 } | 119 } |
| 112 return generate_property_api_h | 120 return generate_property_api_h |
| 113 | 121 |
| 114 if __name__ == '__main__': | 122 if __name__ == '__main__': |
| 115 json5_generator.Maker(CSSPropertyAPIWriter).main() | 123 json5_generator.Maker(CSSPropertyAPIWriter).main() |
| OLD | NEW |