mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-27 12:44:42 +01:00
parent
f41df9f7bd
commit
74cb974455
@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
### Node JS API
|
### Node JS API
|
||||||
|
|
||||||
* Add support for `data`, `lineFeed`, `indentWidth`, and `indentType` options to
|
* Add support for `data`, `includePaths`, `indentedSyntax`, `lineFeed`,
|
||||||
`render()` and `renderSync()`.
|
`indentWidth`, and `indentType` options to `render()` and `renderSync()`.
|
||||||
|
|
||||||
### Dart API
|
### Dart API
|
||||||
|
|
||||||
|
@ -79,12 +79,14 @@ RenderResult _doRender(RenderOptions options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
output = renderString(options.data,
|
output = renderString(options.data,
|
||||||
|
loadPaths: options.includePaths,
|
||||||
indented: options.indentedSyntax ?? false,
|
indented: options.indentedSyntax ?? false,
|
||||||
useSpaces: options.indentType != 'tab',
|
useSpaces: options.indentType != 'tab',
|
||||||
indentWidth: _parseIndentWidth(options.indentWidth),
|
indentWidth: _parseIndentWidth(options.indentWidth),
|
||||||
lineFeed: _parseLineFeed(options.linefeed));
|
lineFeed: _parseLineFeed(options.linefeed));
|
||||||
} else if (options.file != null) {
|
} else if (options.file != null) {
|
||||||
output = render(options.file,
|
output = render(options.file,
|
||||||
|
loadPaths: options.includePaths,
|
||||||
indented: options.indentedSyntax,
|
indented: options.indentedSyntax,
|
||||||
useSpaces: options.indentType != 'tab',
|
useSpaces: options.indentType != 'tab',
|
||||||
indentWidth: _parseIndentWidth(options.indentWidth),
|
indentWidth: _parseIndentWidth(options.indentWidth),
|
||||||
|
@ -9,6 +9,7 @@ import 'package:js/js.dart';
|
|||||||
class RenderOptions {
|
class RenderOptions {
|
||||||
external String get file;
|
external String get file;
|
||||||
external String get data;
|
external String get data;
|
||||||
|
external List<String> get includePaths;
|
||||||
external bool get indentedSyntax;
|
external bool get indentedSyntax;
|
||||||
external String get indentType;
|
external String get indentType;
|
||||||
external dynamic get indentWidth;
|
external dynamic get indentWidth;
|
||||||
@ -17,6 +18,7 @@ class RenderOptions {
|
|||||||
external factory RenderOptions(
|
external factory RenderOptions(
|
||||||
{String file,
|
{String file,
|
||||||
String data,
|
String data,
|
||||||
|
List<String> includePaths,
|
||||||
bool indentedSyntax,
|
bool indentedSyntax,
|
||||||
String indentType,
|
String indentType,
|
||||||
indentWidth,
|
indentWidth,
|
||||||
|
@ -15,6 +15,7 @@ String render(String path,
|
|||||||
{bool indented,
|
{bool indented,
|
||||||
bool color: false,
|
bool color: false,
|
||||||
SyncPackageResolver packageResolver,
|
SyncPackageResolver packageResolver,
|
||||||
|
Iterable<String> loadPaths,
|
||||||
bool useSpaces: true,
|
bool useSpaces: true,
|
||||||
int indentWidth,
|
int indentWidth,
|
||||||
LineFeed lineFeed}) =>
|
LineFeed lineFeed}) =>
|
||||||
@ -22,6 +23,7 @@ String render(String path,
|
|||||||
indented: indented ?? p.extension(path) == '.sass',
|
indented: indented ?? p.extension(path) == '.sass',
|
||||||
color: color,
|
color: color,
|
||||||
packageResolver: packageResolver,
|
packageResolver: packageResolver,
|
||||||
|
loadPaths: loadPaths,
|
||||||
useSpaces: useSpaces,
|
useSpaces: useSpaces,
|
||||||
indentWidth: indentWidth,
|
indentWidth: indentWidth,
|
||||||
lineFeed: lineFeed,
|
lineFeed: lineFeed,
|
||||||
@ -33,6 +35,7 @@ String renderString(String source,
|
|||||||
{bool indented: false,
|
{bool indented: false,
|
||||||
bool color: false,
|
bool color: false,
|
||||||
SyncPackageResolver packageResolver,
|
SyncPackageResolver packageResolver,
|
||||||
|
Iterable<String> loadPaths,
|
||||||
bool useSpaces: true,
|
bool useSpaces: true,
|
||||||
int indentWidth,
|
int indentWidth,
|
||||||
LineFeed lineFeed,
|
LineFeed lineFeed,
|
||||||
@ -40,8 +43,8 @@ String renderString(String source,
|
|||||||
var sassTree = indented
|
var sassTree = indented
|
||||||
? new Stylesheet.parseSass(source, url: url, color: color)
|
? new Stylesheet.parseSass(source, url: url, color: color)
|
||||||
: new Stylesheet.parseScss(source, url: url, color: color);
|
: new Stylesheet.parseScss(source, url: url, color: color);
|
||||||
var cssTree =
|
var cssTree = evaluate(sassTree,
|
||||||
evaluate(sassTree, color: color, packageResolver: packageResolver);
|
color: color, packageResolver: packageResolver, loadPaths: loadPaths);
|
||||||
return toCss(cssTree,
|
return toCss(cssTree,
|
||||||
useSpaces: useSpaces, indentWidth: indentWidth, lineFeed: lineFeed);
|
useSpaces: useSpaces, indentWidth: indentWidth, lineFeed: lineFeed);
|
||||||
}
|
}
|
||||||
|
@ -620,9 +620,12 @@ class _PerformVisitor
|
|||||||
? _tryImportPath
|
? _tryImportPath
|
||||||
: _tryImportPathWithExtensions;
|
: _tryImportPathWithExtensions;
|
||||||
|
|
||||||
var base = p.dirname(p.fromUri(import.span.file.url));
|
if (import.span.file.url != null) {
|
||||||
var resolved = tryPath(p.join(base, path));
|
var base = p.dirname(p.fromUri(import.span.file.url));
|
||||||
if (resolved != null) return resolved;
|
|
||||||
|
var resolved = tryPath(p.join(base, path));
|
||||||
|
if (resolved != null) return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
for (var loadPath in _loadPaths) {
|
for (var loadPath in _loadPaths) {
|
||||||
var resolved = tryPath(p.join(loadPath, path));
|
var resolved = tryPath(p.join(loadPath, path));
|
||||||
|
@ -15,6 +15,10 @@ Future<String> createTempDir() async => (await runHybridExpression(
|
|||||||
Future writeTextFile(String path, String text) => runHybridExpression(
|
Future writeTextFile(String path, String text) => runHybridExpression(
|
||||||
'new File(message[0]).writeAsString(message[1])', [path, text]);
|
'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].
|
/// Recursively deletes the directoy at [path].
|
||||||
Future deleteDirectory(String path) =>
|
Future deleteDirectory(String path) =>
|
||||||
runHybridExpression('new Directory(message).delete(recursive: true)', path);
|
runHybridExpression('new Directory(message).delete(recursive: true)', path);
|
||||||
|
@ -79,6 +79,33 @@ a {
|
|||||||
contains('Either options.data or options.file must be set.'));
|
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", () {
|
test("can render the indented syntax", () {
|
||||||
expect(
|
expect(
|
||||||
_renderSync(
|
_renderSync(
|
||||||
|
Loading…
Reference in New Issue
Block a user