mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 05:41:14 +01:00
Add args support.
It doesn't really do anything yet.
This commit is contained in:
parent
80e111eb56
commit
83c8c1a9b7
@ -4,14 +4,35 @@
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:sass/src/parser.dart';
|
||||
import 'package:sass/src/visitor/perform.dart';
|
||||
import 'package:sass/src/visitor/serialize.dart';
|
||||
|
||||
void main(List<String> args) {
|
||||
var parser = new Parser(new File(args.first).readAsStringSync(),
|
||||
url: p.toUri(args.first));
|
||||
var argParser = new ArgParser()
|
||||
..addOption('precision', hide: true)
|
||||
..addOption('style',
|
||||
abbr: 's',
|
||||
help: 'Output style.',
|
||||
allowed: ['expanded'],
|
||||
defaultsTo: 'expanded')
|
||||
..addFlag('help',
|
||||
abbr: 'h', help: 'Print this usage information.', negatable: false);
|
||||
var options = argParser.parse(args);
|
||||
|
||||
if (options['help']) {
|
||||
print("Compile Sass to CSS.\n");
|
||||
print("Usage: sass <input>\n");
|
||||
print(argParser.usage);
|
||||
exit(64);
|
||||
}
|
||||
|
||||
var file = options.rest.first;
|
||||
var parser =
|
||||
new Parser(new File(file).readAsStringSync(), url: p.toUri(file));
|
||||
var cssTree = new PerformVisitor().visitStylesheet(parser.parse());
|
||||
print(toCss(cssTree));
|
||||
var css = toCss(cssTree);
|
||||
if (css.isNotEmpty) print(css);
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ import 'interface/css.dart';
|
||||
import 'interface/selector.dart';
|
||||
import 'interface/value.dart';
|
||||
|
||||
String toCss(CssNode node) {
|
||||
var visitor = new _SerializeCssVisitor();
|
||||
String toCss(CssNode node, {OutputStyle style}) {
|
||||
var visitor = new _SerializeCssVisitor(style: style);
|
||||
node.accept(visitor);
|
||||
var result = visitor._buffer.toString();
|
||||
if (result.codeUnits.any((codeUnit) => codeUnit > 0x7F)) {
|
||||
@ -42,10 +42,15 @@ String selectorToCss(Selector selector) {
|
||||
|
||||
class _SerializeCssVisitor
|
||||
implements CssVisitor, ValueVisitor, SelectorVisitor {
|
||||
final OutputStyle _style;
|
||||
|
||||
final _buffer = new StringBuffer();
|
||||
|
||||
var _indentation = 0;
|
||||
|
||||
_SerializeCssVisitor({OutputStyle style})
|
||||
: _style = style ?? OutputStyle.expanded;
|
||||
|
||||
void visitStylesheet(CssStylesheet node) {
|
||||
for (var child in node.children) {
|
||||
child.accept(this);
|
||||
@ -408,3 +413,14 @@ class _SerializeCssVisitor
|
||||
_indentation--;
|
||||
}
|
||||
}
|
||||
|
||||
class OutputStyle {
|
||||
static const expanded = const OutputStyle._("expanded");
|
||||
static const nested = const OutputStyle._("nested");
|
||||
|
||||
final String _name;
|
||||
|
||||
const OutputStyle._(this._name);
|
||||
|
||||
String toString() => _name;
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ environment:
|
||||
sdk: '>=1.8.0 <2.0.0'
|
||||
|
||||
dependencies:
|
||||
args: "^0.13.0"
|
||||
charcode: "^1.1.0"
|
||||
collection: "^1.1.0"
|
||||
path: "^1.0.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user