dart-sass/lib/sass.dart
Natalie Weizenbaum d7caf7fbc1 Gracefully handle invalid UTF-8.
This will be even more graceful when dart-lang/sdk#28293 is fixed.
2017-01-06 21:31:29 -08:00

27 lines
950 B
Dart

// 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:path/path.dart' as p;
import 'src/ast/sass.dart';
import 'src/exception.dart';
import 'src/utils.dart';
import 'src/visitor/perform.dart';
import 'src/visitor/serialize.dart';
/// Loads the Sass file at [path], converts it to CSS, and returns the result.
///
/// If [color] is `true`, this will use terminal colors in warnings.
///
/// Throws a [SassException] if conversion fails.
String render(String path, {bool color: false}) {
var contents = readSassFile(path);
var url = p.toUri(path);
var sassTree = p.extension(path) == '.sass'
? new Stylesheet.parseSass(contents, url: url, color: color)
: new Stylesheet.parseScss(contents, url: url, color: color);
var cssTree = evaluate(sassTree, color: color);
return toCss(cssTree);
}