OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 import sys |
| 31 |
| 32 import in_generator |
| 33 import template_expander |
| 34 import name_utilities |
| 35 |
| 36 from make_qualified_names import MakeQualifiedNamesWriter |
| 37 |
| 38 |
| 39 def _interface(tag): |
| 40 if tag['interfaceName']: |
| 41 return tag['interfaceName'] |
| 42 name = name_utilities.upper_first(tag['name']) |
| 43 # FIXME: We shouldn't hard-code HTML here. |
| 44 if name == 'HTML': |
| 45 name = 'Html' |
| 46 return 'HTML%sElement' % name |
| 47 |
| 48 |
| 49 class MakeElementFactoryWriter(MakeQualifiedNamesWriter): |
| 50 defaults = dict(MakeQualifiedNamesWriter.default_parameters, **{ |
| 51 'JSInterfaceName': None, |
| 52 'constructorNeedsCreatedByParser': None, |
| 53 'constructorNeedsFormElement': None, |
| 54 'contextConditional': None, |
| 55 'interfaceName': None, |
| 56 'mapToTagName': None, |
| 57 'noConstructor': None, |
| 58 'wrapperOnlyIfMediaIsAvailable': None, |
| 59 }) |
| 60 default_parameters = dict(MakeQualifiedNamesWriter.default_parameters, **{ |
| 61 'fallbackInterfaceName': None, |
| 62 'namespacePrefix': None, |
| 63 }) |
| 64 filters = dict(MakeQualifiedNamesWriter.filters, **{ |
| 65 'interface': _interface, |
| 66 }) |
| 67 |
| 68 def __init__(self, in_file_paths, enabled_conditions): |
| 69 super(MakeElementFactoryWriter, self).__init__(in_file_paths, enabled_co
nditions) |
| 70 |
| 71 # FIXME: When we start using these element factories, we'll want to |
| 72 # remove the "new" prefix and also have our base class generate |
| 73 # *Names.h and *Names.cpp. |
| 74 self._outputs = { |
| 75 (self.namespace + 'ElementFactory.h'): self.generate_factory_header, |
| 76 (self.namespace + 'ElementFactory.cpp'): self.generate_factory_imple
mentation, |
| 77 } |
| 78 |
| 79 self._template_context.update({ |
| 80 'fallback_interface': self.tags_in_file.parameters['fallbackInterfac
eName'].strip('"') |
| 81 }) |
| 82 |
| 83 @template_expander.use_jinja('ElementFactory.h.tmpl', filters=filters) |
| 84 def generate_factory_header(self): |
| 85 return self._template_context |
| 86 |
| 87 @template_expander.use_jinja('ElementFactory.cpp.tmpl', filters=filters) |
| 88 def generate_factory_implementation(self): |
| 89 return self._template_context |
| 90 |
| 91 |
| 92 if __name__ == "__main__": |
| 93 in_generator.Maker(MakeElementFactoryWriter).main(sys.argv) |
OLD | NEW |