| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class Generate { | 5 class Generate { |
| 6 | 6 |
| 7 // Build up list of all known class selectors in all CSS files. | 7 // Build up list of all known class selectors in all CSS files. |
| 8 static List<String> computeClassSelectors(RuleSet ruleset, classes) { | 8 static List<String> computeClassSelectors(RuleSet ruleset, classes) { |
| 9 for (final selector in ruleset.selectorGroup.selectors) { | 9 for (final selector in ruleset.selectorGroup.selectors) { |
| 10 var selSeqs = selector.simpleSelectorSequences; | 10 var selSeqs = selector.simpleSelectorSequences; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 '// Do not edit.\n\n'); | 33 '// Do not edit.\n\n'); |
| 34 | 34 |
| 35 // Emit class for any @stylet directive. | 35 // Emit class for any @stylet directive. |
| 36 for (final production in stylesheet._topLevels) { | 36 for (final production in stylesheet._topLevels) { |
| 37 if (production is Directive) { | 37 if (production is Directive) { |
| 38 if (production is StyletDirective) { | 38 if (production is StyletDirective) { |
| 39 // TODO(terry): Need safer mechanism for stylets in different files | 39 // TODO(terry): Need safer mechanism for stylets in different files |
| 40 // and stylets with colliding names. | 40 // and stylets with colliding names. |
| 41 buff.add('class ${production.dartClassName} {\n'); | 41 buff.add('class ${production.dartClassName} {\n'); |
| 42 buff.add(' // selector, properties<propertyName, value>\n'); | 42 buff.add(' // selector, properties<propertyName, value>\n'); |
| 43 buff.add(' static final selectors = const {\n'); | 43 buff.add(' static const selectors = const {\n'); |
| 44 | 44 |
| 45 for (final ruleset in production.rulesets) { | 45 for (final ruleset in production.rulesets) { |
| 46 for (final selector in ruleset.selectorGroup.selectors) { | 46 for (final selector in ruleset.selectorGroup.selectors) { |
| 47 var selSeq = selector.simpleSelectorSquences; | 47 var selSeq = selector.simpleSelectorSquences; |
| 48 if (selSeq.length == 1) { | 48 if (selSeq.length == 1) { |
| 49 buff.add(' \'${selSeq.toString()}\' : const {\n'); | 49 buff.add(' \'${selSeq.toString()}\' : const {\n'); |
| 50 } | 50 } |
| 51 } | 51 } |
| 52 | 52 |
| 53 for (final decl in ruleset.declarationGroup.declarations) { | 53 for (final decl in ruleset.declarationGroup.declarations) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 69 knownClasses = computeClassSelectors(production, knownClasses); | 69 knownClasses = computeClassSelectors(production, knownClasses); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Generate all known classes encountered in all processed CSS files. | 73 // Generate all known classes encountered in all processed CSS files. |
| 74 StringBuffer classSelectors = new StringBuffer( | 74 StringBuffer classSelectors = new StringBuffer( |
| 75 'class CSS {\n' + | 75 'class CSS {\n' + |
| 76 ' // CSS class selectors:\n'); | 76 ' // CSS class selectors:\n'); |
| 77 for (final className in knownClasses) { | 77 for (final className in knownClasses) { |
| 78 String classAsDart = className.replaceAll('-', '_').toUpperCase(); | 78 String classAsDart = className.replaceAll('-', '_').toUpperCase(); |
| 79 classSelectors.add(' static final String ${classAsDart} = ' + | 79 classSelectors.add(' static const String ${classAsDart} = ' + |
| 80 '\'${className}\';\n'); | 80 '\'${className}\';\n'); |
| 81 } | 81 } |
| 82 classSelectors.add('}\n'); // End of class selectors. | 82 classSelectors.add('}\n'); // End of class selectors. |
| 83 buff.add(classSelectors.toString()); | 83 buff.add(classSelectors.toString()); |
| 84 | 84 |
| 85 // Write Dart file. | 85 // Write Dart file. |
| 86 String outFile = '${outPath}CSS.dart'; | 86 String outFile = '${outPath}CSS.dart'; |
| 87 files.writeString(outFile, buff.toString()); | 87 files.writeString(outFile, buff.toString()); |
| 88 | 88 |
| 89 return outFile; | 89 return outFile; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 | 92 |
| OLD | NEW |