2016-06-10 01:37:54 +02:00
|
|
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'package:source_span/source_span.dart';
|
|
|
|
|
|
|
|
import '../../visitor/css.dart';
|
2016-07-12 00:13:43 +02:00
|
|
|
import '../parent.dart';
|
2016-06-10 01:37:54 +02:00
|
|
|
import 'node.dart';
|
|
|
|
import 'value.dart';
|
|
|
|
|
2016-07-12 00:13:43 +02:00
|
|
|
class CssAtRule implements CssNode, Parent<CssNode, CssAtRule> {
|
2016-06-10 01:37:54 +02:00
|
|
|
final String name;
|
|
|
|
|
|
|
|
final CssValue<String> value;
|
|
|
|
|
|
|
|
final List<CssNode> children;
|
|
|
|
|
|
|
|
final FileSpan span;
|
|
|
|
|
|
|
|
// TODO: validate that children contains only at-rule and declaration nodes?
|
|
|
|
CssAtRule(this.name, {this.value, Iterable<CssNode> children, this.span})
|
|
|
|
: children = children == null ? null : new List.unmodifiable(children);
|
|
|
|
|
|
|
|
/*=T*/ accept/*<T>*/(CssVisitor/*<T>*/ visitor) =>
|
|
|
|
visitor.visitAtRule(this);
|
|
|
|
|
2016-07-12 00:13:43 +02:00
|
|
|
CssAtRule withChildren(Iterable<CssNode> children) =>
|
|
|
|
new CssAtRule(name, value: value, children: children, span: span);
|
|
|
|
|
2016-06-10 01:37:54 +02:00
|
|
|
String toString() {
|
|
|
|
var buffer = new StringBuffer("@$name");
|
|
|
|
if (value != null) buffer.write(" $value");
|
|
|
|
return children == null ? "$buffer;" : "$buffer {${children.join(" ")}}";
|
|
|
|
}
|
|
|
|
}
|