mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-27 04:34:59 +01:00
parent
f41df9f7bd
commit
74cb974455
@ -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
|
||||
|
||||
|
@ -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),
|
||||
|
@ -9,6 +9,7 @@ import 'package:js/js.dart';
|
||||
class RenderOptions {
|
||||
external String get file;
|
||||
external String get data;
|
||||
external List<String> 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<String> includePaths,
|
||||
bool indentedSyntax,
|
||||
String indentType,
|
||||
indentWidth,
|
||||
|
@ -15,6 +15,7 @@ String render(String path,
|
||||
{bool indented,
|
||||
bool color: false,
|
||||
SyncPackageResolver packageResolver,
|
||||
Iterable<String> 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<String> 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);
|
||||
}
|
||||
|
@ -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));
|
||||
|
@ -15,6 +15,10 @@ Future<String> 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);
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user