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

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: All changes ready to commit Created 7 years, 2 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 | « pkg/csslib/lib/src/analyzer.dart ('k') | pkg/csslib/lib/src/messages.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {
(...skipping 169 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);
210 emit('@include ${node.name}');
211 emit(';');
212 }
213
214 void visitContentDirective(ContentDirective node) {
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
268 void visitExtendDeclaration(ExtendDeclaration node) {
269 emit("@extend ");
270 for (var selector in node.selectors) {
271 selector.visit(this);
272 }
273 }
274
275
235 void visitSelectorGroup(SelectorGroup node) { 276 void visitSelectorGroup(SelectorGroup node) {
236 var selectors = node._selectors; 277 var selectors = node._selectors;
237 var selectorsLength = selectors.length; 278 var selectorsLength = selectors.length;
238 for (var i = 0; i < selectorsLength; i++) { 279 for (var i = 0; i < selectorsLength; i++) {
239 if (i > 0) emit(',$_sp'); 280 if (i > 0) emit(',$_sp');
240 selectors[i].visit(this); 281 selectors[i].visit(this);
241 } 282 }
242 } 283 }
243 284
244 void visitSimpleSelectorSequence(SimpleSelectorSequence node) { 285 void visitSimpleSelectorSequence(SimpleSelectorSequence node) {
245 emit('${node._combinatorToString}'); 286 emit('${node._combinatorToString}');
246 node._selector.visit(this); 287 node._selector.visit(this);
247 } 288 }
248 289
249 void visitSimpleSelector(SimpleSelector node) { 290 void visitSimpleSelector(SimpleSelector node) {
250 emit(node.name); 291 emit(node.name);
251 } 292 }
252 293
253 void visitNamespaceSelector(NamespaceSelector node) { 294 void visitNamespaceSelector(NamespaceSelector node) {
254 emit("${node.namespace}|${node.nameAsSimpleSelector.name}"); 295 emit(node.toString());
255 } 296 }
256 297
257 void visitElementSelector(ElementSelector node) { 298 void visitElementSelector(ElementSelector node) {
258 emit("${node.name}"); 299 emit(node.toString());
259 } 300 }
260 301
261 void visitAttributeSelector(AttributeSelector node) { 302 void visitAttributeSelector(AttributeSelector node) {
262 emit("[${node.name}${node.matchOperator()}${node.valueToString()}]"); 303 emit(node.toString());
263 } 304 }
264 305
265 void visitIdSelector(IdSelector node) { 306 void visitIdSelector(IdSelector node) {
266 emit("#${node.name}"); 307 emit(node.toString());
267 } 308 }
268 309
269 void visitClassSelector(ClassSelector node) { 310 void visitClassSelector(ClassSelector node) {
270 emit(".${node.name}"); 311 emit(node.toString());
271 } 312 }
272 313
273 void visitPseudoClassSelector(PseudoClassSelector node) { 314 void visitPseudoClassSelector(PseudoClassSelector node) {
274 emit(":${node.name}"); 315 emit(node.toString());
275 } 316 }
276 317
277 void visitPseudoElementSelector(PseudoElementSelector node) { 318 void visitPseudoElementSelector(PseudoElementSelector node) {
278 emit("::${node.name}"); 319 emit(node.toString());
279 } 320 }
280 321
281 void visitPseudoClassFunctionSelector(PseudoClassFunctionSelector node) { 322 void visitPseudoClassFunctionSelector(PseudoClassFunctionSelector node) {
282 emit(":${node.name}("); 323 emit(":${node.name}(");
283 node.expression.visit(this); 324 node.expression.visit(this);
284 emit(')'); 325 emit(')');
285 } 326 }
286 327
287 void visitPseudoElementFunctionSelector(PseudoElementFunctionSelector node) { 328 void visitPseudoElementFunctionSelector(PseudoElementFunctionSelector node) {
288 emit("::${node.name}("); 329 emit("::${node.name}(");
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 508
468 void visitWildcard(Wildcard node) { 509 void visitWildcard(Wildcard node) {
469 emit('*'); 510 emit('*');
470 } 511 }
471 512
472 void visitDartStyleExpression(DartStyleExpression node) { 513 void visitDartStyleExpression(DartStyleExpression node) {
473 // TODO(terry): TBD 514 // TODO(terry): TBD
474 throw UnimplementedError; 515 throw UnimplementedError;
475 } 516 }
476 } 517 }
OLDNEW
« no previous file with comments | « pkg/csslib/lib/src/analyzer.dart ('k') | pkg/csslib/lib/src/messages.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698