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

Side by Side Diff: tools/dom/scripts/css_code_generator.py

Issue 448413002: Do regular expression for camelCase CSS processing in JS. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
4 # for details. All rights reserved. Use of this source code is governed by a 4 # for details. All rights reserved. Use of this source code is governed by a
5 # BSD-style license that can be found in the LICENSE file. 5 # BSD-style license that can be found in the LICENSE file.
6 6
7 """Generates CSSStyleDeclaration template file from css property definitions 7 """Generates CSSStyleDeclaration template file from css property definitions
8 defined in WebKit.""" 8 defined in WebKit."""
9 9
10 import tempfile, os 10 import tempfile, os
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 void setProperty(String propertyName, String value, [String priority]) { 119 void setProperty(String propertyName, String value, [String priority]) {
120 if (_supportsProperty(_camelCase(propertyName))) { 120 if (_supportsProperty(_camelCase(propertyName))) {
121 return _setPropertyHelper(propertyName, value, priority); 121 return _setPropertyHelper(propertyName, value, priority);
122 } else { 122 } else {
123 return _setPropertyHelper(Device.cssPrefix + propertyName, value, 123 return _setPropertyHelper(Device.cssPrefix + propertyName, value,
124 priority); 124 priority);
125 } 125 }
126 } 126 }
127 127
128 static String _camelCase(String hyphenated) { 128 static String _camelCase(String hyphenated) {
129 $if DART2JS
130 var replacedMs = JS('String', r'#.replace(/^-ms-/, "ms-")', hyphenated);
131
132 var fToUpper = const JS_CONST(
133 r'function(_, letter) { return letter.toUpperCase(); }');
134 return JS('String', r'#.replace(/-([\da-z])/ig, #)', replacedMs, fToUpper);
135 $else
129 // The "ms" prefix is always lowercased. 136 // The "ms" prefix is always lowercased.
sra1 2014/08/08 00:49:28 This comment should go outside the $if
130 return hyphenated.replaceFirst(new RegExp('^-ms-'), 'ms-').replaceAllMapped( 137 return hyphenated.replaceFirst(new RegExp('^-ms-'), 'ms-').replaceAllMapped(
131 new RegExp('-([a-z]+)', caseSensitive: false), 138 new RegExp('-([a-z]+)', caseSensitive: false),
132 (match) => match[0][1].toUpperCase() + match[0].substring(2)); 139 (match) => match[0][1].toUpperCase() + match[0].substring(2));
140 $endif
133 } 141 }
134 142
135 $if DART2JS 143 $if DART2JS
136 void _setPropertyHelper(String propertyName, String value, [String priority]) { 144 void _setPropertyHelper(String propertyName, String value, [String priority]) {
137 // try/catch for IE9 which throws on unsupported values. 145 // try/catch for IE9 which throws on unsupported values.
138 try { 146 try {
139 if (value == null) value = ''; 147 if (value == null) value = '';
140 if (priority == null) { 148 if (priority == null) {
141 priority = ''; 149 priority = '';
142 } 150 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 class_lines.append(annotated[base_css_name]) 236 class_lines.append(annotated[base_css_name])
229 class_lines.append(""" 237 class_lines.append("""
230 void set %s(String value) { 238 void set %s(String value) {
231 setProperty('%s', value, ''); 239 setProperty('%s', value, '');
232 } 240 }
233 """ % (camel_case_name, css_name)) 241 """ % (camel_case_name, css_name))
234 242
235 class_file.write(''.join(class_lines)); 243 class_file.write(''.join(class_lines));
236 class_file.write('}\n') 244 class_file.write('}\n')
237 class_file.close() 245 class_file.close()
OLDNEW
« no previous file with comments | « sdk/lib/html/dartium/html_dartium.dart ('k') | tools/dom/templates/html/dart2js/html_dart2js.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698