1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
10 """<!-- Copyright %(year)d The Chromium Authors. All rights reserved.
11 Use of this source code is governed by a BSD-style license that can be
12 found in the LICENSE file. -->
14 <!-- NOTE: this file is generated from "%(source)s". Do not modify directly. -->
18 <link rel="import" href="chrome://resources/polymer/polymer/polymer.html">
19 <link rel="import" href="/webui_generator/webui-view.html">
22 <polymer-element name="%(element_name)s" extends="webui-view">
24 <script src="%(js_file_path)s"></script>
29 """// Copyright %(year)d The Chromium Authors. All rights reserved.
30 // Use of this source code is governed by a BSD-style license that can be
31 // found in the LICENSE file.
33 // NOTE: this file is generated from "%(source)s". Do not modify directly.
36 Polymer('%(element_name)s', (function() {
43 initialize: function() {},
44 contextChanged: function(changedKeys) {},
46 initChildren_: function() {
47 %(init_children_body)s
50 initContext_: function() {
57 def GetCommonSubistitutions(declaration
):
59 subs
['year'] = datetime
.date
.today().year
60 subs
['element_name'] = declaration
.type.replace('_', '-') + '-view'
61 subs
['source'] = declaration
.path
64 def GenChildrenIncludes(children
):
66 for declaration
in set(children
.itervalues()):
67 lines
.append('<link rel="import" href="/%s">' %
68 declaration
.html_view_html_include_path
)
69 return '\n'.join(lines
)
71 def GenHTMLFile(declaration
):
72 subs
= GetCommonSubistitutions(declaration
)
73 subs
['js_file_path'] = subs
['element_name'] + '.js'
74 subs
['children_includes'] = GenChildrenIncludes(declaration
.children
)
75 return HTML_FILE_TEMPLATE
% subs
77 def GenInitChildrenBody(children
):
79 lines
.append(' var child = null;');
81 lines
.append(' child = this.shadowRoot.querySelector(\'[wugid="%s"]\');'
83 lines
.append(' if (!child)');
84 lines
.append(' console.error(this.path_ + \'$%s not found.\');' % id);
85 lines
.append(' else');
86 lines
.append(' child.setPath_(this.path_ + \'$%s\');' % id)
87 return '\n'.join(lines
)
89 def GenInitContextBody(fields
):
93 if field
.type in ['integer', 'double']:
94 value
= str(field
.default_value
)
95 elif field
.type == 'boolean':
96 value
= 'true' if field
.default_value
else 'false'
97 elif field
.type == 'string':
98 value
= '\'%s\'' % field
.default_value
99 elif field
.type == 'string_list':
101 ', '.join('\'%s\'' % s
for s
in field
.default_value
) + ']'
102 lines
.append(' this.context.set(\'%s\', %s);' % (field
.id, value
))
103 lines
.append(' this.context.getChangesAndReset();')
104 return '\n'.join(lines
)
106 def GenJSFile(declaration
):
107 subs
= GetCommonSubistitutions(declaration
)
108 subs
['type'] = declaration
.type
109 subs
['init_children_body'] = GenInitChildrenBody(declaration
.children
)
110 subs
['init_context_body'] = GenInitContextBody(declaration
.fields
)
111 return JS_FILE_TEMPLATE
% subs