2017-06-03 00:42:22 +02:00
|
|
|
// Copyright 2017 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 'ast/sass.dart';
|
|
|
|
import 'io.dart';
|
|
|
|
import 'sync_package_resolver.dart';
|
2017-07-07 04:29:39 +02:00
|
|
|
import 'util/path.dart';
|
2017-07-08 02:25:52 +02:00
|
|
|
import 'visitor/evaluate.dart';
|
2017-06-03 00:42:22 +02:00
|
|
|
import 'visitor/serialize.dart';
|
|
|
|
|
2017-07-08 02:03:31 +02:00
|
|
|
/// Like [compile] in `lib/sass.dart`, but provides more options to support the
|
2017-06-03 00:42:22 +02:00
|
|
|
/// node-sass compatible API.
|
2017-07-09 23:52:14 +02:00
|
|
|
CompileResult compile(String path,
|
2017-07-07 10:40:15 +02:00
|
|
|
{bool indented,
|
|
|
|
bool color: false,
|
2017-07-07 09:57:10 +02:00
|
|
|
SyncPackageResolver packageResolver,
|
2017-07-07 23:50:12 +02:00
|
|
|
Iterable<String> loadPaths,
|
2017-07-08 01:39:58 +02:00
|
|
|
OutputStyle style,
|
2017-07-07 09:57:10 +02:00
|
|
|
bool useSpaces: true,
|
|
|
|
int indentWidth,
|
|
|
|
LineFeed lineFeed}) =>
|
2017-07-08 02:03:31 +02:00
|
|
|
compileString(readFile(path),
|
2017-07-07 10:40:15 +02:00
|
|
|
indented: indented ?? p.extension(path) == '.sass',
|
2017-07-07 09:57:10 +02:00
|
|
|
color: color,
|
|
|
|
packageResolver: packageResolver,
|
2017-07-08 01:39:58 +02:00
|
|
|
style: style,
|
2017-07-07 23:50:12 +02:00
|
|
|
loadPaths: loadPaths,
|
2017-07-07 09:57:10 +02:00
|
|
|
useSpaces: useSpaces,
|
|
|
|
indentWidth: indentWidth,
|
|
|
|
lineFeed: lineFeed,
|
|
|
|
url: p.toUri(path));
|
|
|
|
|
2017-07-08 02:03:31 +02:00
|
|
|
/// Like [compileString] in `lib/sass.dart`, but provides more options to support
|
2017-07-07 09:57:10 +02:00
|
|
|
/// the node-sass compatible API.
|
2017-07-09 23:52:14 +02:00
|
|
|
CompileResult compileString(String source,
|
2017-07-07 09:57:10 +02:00
|
|
|
{bool indented: false,
|
|
|
|
bool color: false,
|
2017-06-03 00:42:22 +02:00
|
|
|
SyncPackageResolver packageResolver,
|
2017-07-07 23:50:12 +02:00
|
|
|
Iterable<String> loadPaths,
|
2017-07-08 01:39:58 +02:00
|
|
|
OutputStyle style,
|
2017-06-03 00:42:22 +02:00
|
|
|
bool useSpaces: true,
|
2017-06-16 00:19:26 +02:00
|
|
|
int indentWidth,
|
2017-07-07 09:57:10 +02:00
|
|
|
LineFeed lineFeed,
|
|
|
|
url}) {
|
|
|
|
var sassTree = indented
|
|
|
|
? new Stylesheet.parseSass(source, url: url, color: color)
|
|
|
|
: new Stylesheet.parseScss(source, url: url, color: color);
|
2017-07-09 23:52:14 +02:00
|
|
|
var evaluateResult = evaluate(sassTree,
|
2017-07-07 23:50:12 +02:00
|
|
|
color: color, packageResolver: packageResolver, loadPaths: loadPaths);
|
2017-07-09 23:52:14 +02:00
|
|
|
var css = serialize(evaluateResult.stylesheet,
|
2017-07-08 01:39:58 +02:00
|
|
|
style: style,
|
|
|
|
useSpaces: useSpaces,
|
|
|
|
indentWidth: indentWidth,
|
|
|
|
lineFeed: lineFeed);
|
2017-07-09 23:52:14 +02:00
|
|
|
|
|
|
|
return new CompileResult(css, evaluateResult.includedUrls);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The result of compiling a Sass document to CSS, along with metadata about
|
|
|
|
/// the compilation process.
|
|
|
|
class CompileResult {
|
|
|
|
/// The compiled CSS.
|
|
|
|
final String css;
|
|
|
|
|
|
|
|
/// The URLs that were loaded during the compilation, including the main
|
|
|
|
/// file's.
|
|
|
|
final Set<Uri> includedUrls;
|
|
|
|
|
|
|
|
CompileResult(this.css, this.includedUrls);
|
2017-06-03 00:42:22 +02:00
|
|
|
}
|