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