Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Fix document when returning both file and contents in custom impo…
Browse files Browse the repository at this point in the history
…rter
  • Loading branch information
mtsmfm committed Sep 22, 2018
1 parent 746759c commit 5e54138
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Function Parameters and Information:
* `url (String)` - the path in import **as-is**, which [LibSass] encountered
* `prev (String)` - the previously resolved path
* `done (Function)` - a callback function to invoke on async completion, takes an object literal containing
* `file (String)` - an alternate path for [LibSass] to use **OR**
* `file (String)` - an alternate path for [LibSass] to use
* `contents (String)` - the imported contents (for example, read from memory or the file system)

Handles when [LibSass] encounters the `@import` directive. A custom importer allows extension of the [LibSass] engine in both a synchronous and asynchronous manner. In both cases, the goal is to either `return` or call `done()` with an object literal. Depending on the value of the object literal, one of two things will happen.
Expand All @@ -113,6 +113,9 @@ When returning or calling `done()` with `{ file: "String" }`, the new file path

When returning or calling `done()` with `{ contents: "String" }`, the string value will be used as if the file was read in through an external source.

When returning both `file` and `contents`, `file` is considered as imported file path.
When returning only `contents`, imported file path is considered as import url. As the result, [Result Object](#result-object)'s `includedFiles` contain a file path might not exist. It's highly recommended to return not only `contents` but also `file`.

Starting from v3.0.0:

* `this` refers to a contextual scope for the immediate run of `sass.render` or `sass.renderSync`
Expand Down
2 changes: 2 additions & 0 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ describe('api', function() {
}
}, function(error, result) {
assert.equal(result.css.toString().trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
assert.deepEqual(result.stats.includedFiles.sort(), [fixture('include-files/index.scss').replace(/\\/g, '/'), '/some/other/path.scss'].sort());
done();
});
});
Expand Down Expand Up @@ -516,6 +517,7 @@ describe('api', function() {
}
}, function(error, result) {
assert.equal(result.css.toString().trim(), 'div {\n color: yellow; }\n\ndiv {\n color: yellow; }');
assert.deepEqual(result.stats.includedFiles, ['bar', 'foo']);
done();
});
});
Expand Down

0 comments on commit 5e54138

Please sign in to comment.