🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

node-sass-css-importer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-sass-css-importer - npm Package Compare versions

Comparing version
0.0.1
to
0.0.2
LICENCE

Sorry, the diff of this file is not supported yet

+34
# Node Sass CSS importer.
The Node Sass CSS Importer allows you to import a CSS file into Sass. Just like the [Sass CSS importer](https://github.com/chriseppstein/sass-css-importer).
## Stylesheet Syntax
The `.css` extension triggers special behavior in Sass so you cannot
import a file with a CSS extension. To work around this, you must use a
special prefix on the import string and omit the extension.
```scss
@import "CSS:some_folder/some_css_file"
```
## Installation
```
npm install node-sass-css-importer --save[-dev]
```
## Usage
```js
var sass = require('node-sass')
, CssImporter = require('node-sass-css-importer')({
import_paths: ['app/assets/stylesheets', 'app/assets/components']
});
sass.renderSync({
file: 'source.scss',
importer: [CssImporter]
});
```
body {
padding: 10px;
}
html {
font-size: 10px; }
body {
padding: 10px; }
body {
padding: 25px;
}
html {
font-size: 10px;
}
@import "CSS:body";
var fs = require('fs')
, path = require('path')
, assert = require('assert');
var node = require('node-sass')
, cssImporter = require('../');
node.render({
file: path.join(__dirname, 'source.scss'),
importer: cssImporter({import_paths: [path.join(__dirname, 'precedence')]})
}, function(err, actual) {
assert.equal(err, null);
fs.readFile(path.join(__dirname, 'expected.css'), function(err, expected) {
assert.equal(err, null);
assert.equal(actual.css.toString(), expected.toString());
});
});
node.render({
data: 'html{font-size: 10px}@import "CSS:body";',
importer: cssImporter({import_paths: [__dirname]})
}, function(err, actual) {
assert.equal(err, null);
fs.readFile(path.join(__dirname, 'expected.css'), function(err, expected) {
assert.equal(err, null);
assert.equal(actual.css.toString(), expected.toString());
});
});
+16
-7
var fs = require('fs')
, path = require('path');
var sass = require('node-sass');
module.exports = function(options) {
options = options || {};
options = options || {import_paths: []};
var import_paths = options.import_paths || []
, import_paths_len = import_paths.length;
var import_paths
, import_paths_len;

@@ -17,6 +15,16 @@ return function(url, prev, done) {

import_paths = options.import_paths.slice();
if (fs.existsSync(prev)) {
import_paths.unshift(path.dirname(prev));
}
import_paths_len = import_paths.length;
if (import_paths_len === 0) {
return done();
}
var css_path = url.slice(4) + '.css'
, css_filepath, i, import_path;
, css_filepath, i = 0, import_path;
for (i = 0; i < import_paths_len; i++) {
for (; i < import_paths_len; ++i) {
import_path = import_paths[i];

@@ -29,2 +37,3 @@ css_filepath = path.join(import_path, css_path);

});
break;
}

@@ -31,0 +40,0 @@ }

{
"name": "node-sass-css-importer",
"version": "0.0.1",
"version": "0.0.2",
"description": "css importer for node-sass",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test/test.js"
},

@@ -25,5 +25,5 @@ "repository": {

"homepage": "https://github.com/fetch/node-sass-css-importer",
"dependencies": {
"node-sass": "^3.2.0"
"devDependencies": {
"node-sass": "^3.3.2"
}
}