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

Side by Side Diff: pkg/csslib/lib/src/css_printer.dart

Issue 23819036: Support for @mixin, @include and @extend (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: mixin w/o parameters Created 7 years, 3 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 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of csslib.visitor; 5 part of csslib.visitor;
6 6
7 /** 7 /**
8 * Visitor that produces a formatted string representation of the CSS tree. 8 * Visitor that produces a formatted string representation of the CSS tree.
9 */ 9 */
10 class CssPrinter extends Visitor { 10 class CssPrinter extends Visitor {
nweiz 2013/09/18 22:40:54 If this is printing the CSS tree, why does it need
terry 2013/10/09 03:40:33 Good point done for completness @mixin and @includ
11 StringBuffer _buff = new StringBuffer(); 11 StringBuffer _buff = new StringBuffer();
12 bool prettyPrint = true; 12 bool prettyPrint = true;
13 13
14 /** 14 /**
15 * Walk the [tree] Stylesheet. [pretty] if true emits line breaks, extra 15 * Walk the [tree] Stylesheet. [pretty] if true emits line breaks, extra
16 * spaces, friendly property values, etc., if false emits compacted output. 16 * spaces, friendly property values, etc., if false emits compacted output.
17 */ 17 */
18 void visitTree(StyleSheet tree, {bool pretty: false}) { 18 void visitTree(StyleSheet tree, {bool pretty: false}) {
19 prettyPrint = pretty; 19 prettyPrint = pretty;
20 _buff = new StringBuffer(); 20 _buff = new StringBuffer();
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 180 }
181 } 181 }
182 emit(';'); 182 emit(';');
183 } 183 }
184 184
185 void visitVarDefinitionDirective(VarDefinitionDirective node) { 185 void visitVarDefinitionDirective(VarDefinitionDirective node) {
186 visitVarDefinition(node.def); 186 visitVarDefinition(node.def);
187 emit(';$_newLine'); 187 emit(';$_newLine');
188 } 188 }
189 189
190 void visitMixinRulesetDirective(MixinRulesetDirective node) {
191 emit('@mixin ${node.name} {');
192 for (var ruleset in node.rulesets) {
193 ruleset.visit(this);
194 }
195 emit('}');
196 }
197
198 void visitMixinDeclarationDirective(MixinDeclarationDirective node) {
199 emit('@mixin ${node.name} {\n');
200 visitDeclarationGroup(node.declarations);
201 emit('}');
202 }
203
204 /**
205 * Added optional newLine for handling @include at top-level vs/ inside of
206 * a declaration group.
207 */
208 void visitIncludeDirective(IncludeDirective node, [bool topLevel = true]) {
209 if (topLevel) emit(_newLine); // Emit newline for top-level @include.
nweiz 2013/09/18 22:40:54 Unnecessary spaces before the comment.
terry 2013/10/09 03:40:33 Done.
210 emit('@include ${node.name}');
211 if (topLevel) emit(';');
nweiz 2013/09/18 22:40:54 Why wouldn't non-top-level @includes have a semico
terry 2013/10/09 03:40:33 removed test.On 2013/09/18 22:40:54, nweiz wrote:
212 }
213
214 void visitContentDirective(ContentDirective node) {
nweiz 2013/09/18 22:40:54 If you don't support content directives yet, just
terry 2013/10/09 03:40:33 Place holder have errors for content directive in
215 // TODO(terry): TBD
216 }
217
190 void visitRuleSet(RuleSet node) { 218 void visitRuleSet(RuleSet node) {
191 emit("$_newLine"); 219 emit("$_newLine");
192 node._selectorGroup.visit(this); 220 node._selectorGroup.visit(this);
193 emit(" {$_newLine"); 221 emit(" {$_newLine");
194 node._declarationGroup.visit(this); 222 node._declarationGroup.visit(this);
195 emit("}"); 223 emit("}");
196 } 224 }
197 225
198 void visitDeclarationGroup(DeclarationGroup node) { 226 void visitDeclarationGroup(DeclarationGroup node) {
199 var declarations = node._declarations; 227 var declarations = node._declarations;
(...skipping 25 matching lines...) Expand all
225 node._expression.visit(this); 253 node._expression.visit(this);
226 254
227 emit("${importantAsString()}"); 255 emit("${importantAsString()}");
228 } 256 }
229 257
230 void visitVarDefinition(VarDefinition node) { 258 void visitVarDefinition(VarDefinition node) {
231 emit("var-${node.definedName}: "); 259 emit("var-${node.definedName}: ");
232 node._expression.visit(this); 260 node._expression.visit(this);
233 } 261 }
234 262
263 void visitIncludeMixinAtDeclaration(IncludeMixinAtDeclaration node) {
264 // Don't emit a new line we're inside of a declaration group.
265 visitIncludeDirective(node.include, false);
266 }
267
235 void visitSelectorGroup(SelectorGroup node) { 268 void visitSelectorGroup(SelectorGroup node) {
236 var selectors = node._selectors; 269 var selectors = node._selectors;
237 var selectorsLength = selectors.length; 270 var selectorsLength = selectors.length;
238 for (var i = 0; i < selectorsLength; i++) { 271 for (var i = 0; i < selectorsLength; i++) {
239 if (i > 0) emit(',$_sp'); 272 if (i > 0) emit(',$_sp');
240 selectors[i].visit(this); 273 selectors[i].visit(this);
241 } 274 }
242 } 275 }
243 276
244 void visitSimpleSelectorSequence(SimpleSelectorSequence node) { 277 void visitSimpleSelectorSequence(SimpleSelectorSequence node) {
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 500
468 void visitWildcard(Wildcard node) { 501 void visitWildcard(Wildcard node) {
469 emit('*'); 502 emit('*');
470 } 503 }
471 504
472 void visitDartStyleExpression(DartStyleExpression node) { 505 void visitDartStyleExpression(DartStyleExpression node) {
473 // TODO(terry): TBD 506 // TODO(terry): TBD
474 throw UnimplementedError; 507 throw UnimplementedError;
475 } 508 }
476 } 509 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698