diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d820f59..03e3f835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,8 @@ ### Node JS API -* Add support for `data`, `lineFeed`, `indentWidth`, and `indentType` options to - `render()` and `renderSync()`. +* Add support for `data`, `includePaths`, `indentedSyntax`, `lineFeed`, + `indentWidth`, and `indentType` options to `render()` and `renderSync()`. ### Dart API diff --git a/lib/src/node.dart b/lib/src/node.dart index cf1fe520..5f212b44 100644 --- a/lib/src/node.dart +++ b/lib/src/node.dart @@ -79,12 +79,14 @@ RenderResult _doRender(RenderOptions options) { } output = renderString(options.data, + loadPaths: options.includePaths, indented: options.indentedSyntax ?? false, useSpaces: options.indentType != 'tab', indentWidth: _parseIndentWidth(options.indentWidth), lineFeed: _parseLineFeed(options.linefeed)); } else if (options.file != null) { output = render(options.file, + loadPaths: options.includePaths, indented: options.indentedSyntax, useSpaces: options.indentType != 'tab', indentWidth: _parseIndentWidth(options.indentWidth), diff --git a/lib/src/node/render_options.dart b/lib/src/node/render_options.dart index f707843d..3466a8d7 100644 --- a/lib/src/node/render_options.dart +++ b/lib/src/node/render_options.dart @@ -9,6 +9,7 @@ import 'package:js/js.dart'; class RenderOptions { external String get file; external String get data; + external List get includePaths; external bool get indentedSyntax; external String get indentType; external dynamic get indentWidth; @@ -17,6 +18,7 @@ class RenderOptions { external factory RenderOptions( {String file, String data, + List includePaths, bool indentedSyntax, String indentType, indentWidth, diff --git a/lib/src/render.dart b/lib/src/render.dart index 26368053..0cc28f21 100644 --- a/lib/src/render.dart +++ b/lib/src/render.dart @@ -15,6 +15,7 @@ String render(String path, {bool indented, bool color: false, SyncPackageResolver packageResolver, + Iterable loadPaths, bool useSpaces: true, int indentWidth, LineFeed lineFeed}) => @@ -22,6 +23,7 @@ String render(String path, indented: indented ?? p.extension(path) == '.sass', color: color, packageResolver: packageResolver, + loadPaths: loadPaths, useSpaces: useSpaces, indentWidth: indentWidth, lineFeed: lineFeed, @@ -33,6 +35,7 @@ String renderString(String source, {bool indented: false, bool color: false, SyncPackageResolver packageResolver, + Iterable loadPaths, bool useSpaces: true, int indentWidth, LineFeed lineFeed, @@ -40,8 +43,8 @@ String renderString(String source, var sassTree = indented ? new Stylesheet.parseSass(source, url: url, color: color) : new Stylesheet.parseScss(source, url: url, color: color); - var cssTree = - evaluate(sassTree, color: color, packageResolver: packageResolver); + var cssTree = evaluate(sassTree, + color: color, packageResolver: packageResolver, loadPaths: loadPaths); return toCss(cssTree, useSpaces: useSpaces, indentWidth: indentWidth, lineFeed: lineFeed); } diff --git a/lib/src/visitor/perform.dart b/lib/src/visitor/perform.dart index 6b7863f0..23740486 100644 --- a/lib/src/visitor/perform.dart +++ b/lib/src/visitor/perform.dart @@ -620,9 +620,12 @@ class _PerformVisitor ? _tryImportPath : _tryImportPathWithExtensions; - var base = p.dirname(p.fromUri(import.span.file.url)); - var resolved = tryPath(p.join(base, path)); - if (resolved != null) return resolved; + if (import.span.file.url != null) { + var base = p.dirname(p.fromUri(import.span.file.url)); + + var resolved = tryPath(p.join(base, path)); + if (resolved != null) return resolved; + } for (var loadPath in _loadPaths) { var resolved = tryPath(p.join(loadPath, path)); diff --git a/test/hybrid.dart b/test/hybrid.dart index aec1d9a7..cb41f1a3 100644 --- a/test/hybrid.dart +++ b/test/hybrid.dart @@ -15,6 +15,10 @@ Future createTempDir() async => (await runHybridExpression( Future writeTextFile(String path, String text) => runHybridExpression( 'new File(message[0]).writeAsString(message[1])', [path, text]); +/// Creates a directoy at [path]. +Future createDirectory(String path) => + runHybridExpression('new Directory(message).create()', path); + /// Recursively deletes the directoy at [path]. Future deleteDirectory(String path) => runHybridExpression('new Directory(message).delete(recursive: true)', path); diff --git a/test/node_api_test.dart b/test/node_api_test.dart index 6fb91274..53a1a898 100644 --- a/test/node_api_test.dart +++ b/test/node_api_test.dart @@ -79,6 +79,33 @@ a { contains('Either options.data or options.file must be set.')); }); + test("supports load paths", () { + expect( + _renderSync(new RenderOptions( + data: "@import 'test'", includePaths: [sandbox])), + equals(''' +a { + b: c; +}''')); + }); + + test("supports relative paths in preference to load paths", () async { + await createDirectory(p.join(sandbox, 'sub')); + var subPath = p.join(sandbox, 'sub/test.scss'); + await writeTextFile(subPath, 'x {y: z}'); + + var importerPath = p.join(sandbox, 'importer.scss'); + await writeTextFile(importerPath, '@import "test"'); + + expect( + _renderSync(new RenderOptions( + file: importerPath, includePaths: [p.join(sandbox, 'sub')])), + equals(''' +a { + b: c; +}''')); + }); + test("can render the indented syntax", () { expect( _renderSync(