Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(293)

Side by Side Diff: Source/build/scripts/make_element_type_helpers.py

Issue 175693007: Generate isHTML*Element() / toHTML*Element() helper functions (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make toHTMLObjectElement() work for FormAssociatedElement input Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/build/scripts/scripts.gypi » ('j') | Source/core/html/HTMLObjectElement.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2014 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 sys
7 from collections import defaultdict
8
9 import hasher
10 import in_generator
11 import name_utilities
12 import template_expander
13
14 from in_file import InFile
15
16
17 class MakeElementTypeHelpersWriter(in_generator.Writer):
18 defaults = {
19 'interfaceName': None,
20 'noConstructor': None,
21 'JSInterfaceName': None,
22 'constructorNeedsCreatedByParser': None,
23 'constructorNeedsFormElement': None,
24 'contextConditional': None,
25 'interfaceName': None,
26 'noConstructor': None,
27 'runtimeEnabled': None,
28 }
29 default_parameters = {
30 'attrsNullNamespace': None,
31 'namespace': '',
32 'namespacePrefix': '',
33 'namespaceURI': '',
34 'fallbackInterfaceName': '',
35 'fallbackJSInterfaceName': '',
36 }
37 filters = {
38 'hash': hasher.hash,
39 }
40
41 def __init__(self, in_file_path):
42 super(MakeElementTypeHelpersWriter, self).__init__(in_file_path)
43
44 self.namespace = self.in_file.parameters['namespace'].strip('"')
45
46 assert self.namespace, 'A namespace is required.'
47
48 self._outputs = {
49 (self.namespace + "ElementTypeHelpers.h"): self.generate_helper_head er,
50 }
51
52 self._template_context = {
53 'namespace': self.namespace,
54 'tags': self.in_file.name_dictionaries,
55 }
56
57 tags = self._template_context['tags']
58 interface_counts = defaultdict(int)
59 for tag in tags:
60 tag['interface'] = self._interface(tag)
61 interface_counts[tag['interface']] += 1
62
63 for tag in tags:
64 tag['multipleTagNames'] = interface_counts[tag['interface']] > 1
65
66 @template_expander.use_jinja("ElementTypeHelpers.h.tmpl", filters=filters)
67 def generate_helper_header(self):
68 return self._template_context
69
70 def _interface(self, tag):
71 if tag['interfaceName']:
72 return tag['interfaceName']
73 name = name_utilities.upper_first(tag['name'])
74 # FIXME: We shouldn't hard-code HTML here.
75 if name == 'HTML':
76 name = 'Html'
77 dash = name.find('-')
78 while dash != -1:
79 name = name[:dash] + name[dash + 1].upper() + name[dash + 2:]
80 dash = name.find('-')
81 return '%s%sElement' % (self.namespace, name)
82
83 if __name__ == "__main__":
84 in_generator.Maker(MakeElementTypeHelpersWriter).main(sys.argv)
OLDNEW
« no previous file with comments | « no previous file | Source/build/scripts/scripts.gypi » ('j') | Source/core/html/HTMLObjectElement.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698