Commit 90308d8d by Andrew Nesbitt

Merge pull request #32 from gonghao/master

add scss include_path support
parents 5d331102 c25b1b5d
......@@ -13,9 +13,21 @@ Find it on npm: <http://search.npmjs.org/#/node-sass>
## Usage
var sass = require('node-sass');
sass.render(scss_content, callback [, options]);
Especially, the options argument is optional. It support two attribute: `include_paths` and `output_style`, both of them are optional.
`include_paths` is an `Array`, you can add a sass import path.
`output_style` is a `String`, its value should be one of `'nested', 'expanded', 'compact', 'compressed'`.
[Important: currently the argument `output_style` has some problem which may cause the output css becomes nothing because of the libsass, so you should not use it now!]
Here is an example:
var sass = require('node-sass');
sass.render('body{background:blue; a{color:black;}}', function(err, css){
console.log(css)
});
}/*, { include_paths: [ 'lib/', 'mod/' ], output_style: 'compressed' }*/);
## Connect/Express middleware
......
......@@ -48,11 +48,14 @@ Handle<Value> Render(const Arguments& args) {
sass_context* ctx = sass_new_context();
String::AsciiValue astr(args[0]);
Local<Function> callback = Local<Function>::Cast(args[1]);
String::AsciiValue bstr(args[2]);
ctx->source_string = new char[strlen(*astr)+1];
strcpy(ctx->source_string, *astr);
ctx->options.include_paths = 0;
ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.include_paths = new char[strlen(*bstr)+1];
strcpy(ctx->options.include_paths, *bstr);
// ctx->options.output_style = SASS_STYLE_NESTED;
ctx->options.output_style = args[3]->Int32Value();
ctx->callback = Persistent<Function>::New(callback);
ctx->request.data = ctx;
......
......@@ -13,6 +13,22 @@ try {
if (binding === null) {
throw new Error('Cannot find appropriate binary library for node-sass');
}
exports.render = binding.render
var toString = Object.prototype.toString;
SASS_OUTPUT_STYLE = {
nested: 0,
expanded: 1,
compact: 2,
compressed: 3
};
exports.render = function(css, callback, options) {
var paths, style;
if (toString.call(options) !== '[object Object]') {
options = {};
}
paths = options.include_paths || [];
if (!((style = options.output_style) in SASS_OUTPUT_STYLE)) {
style = 'nested';
}
return binding.render(css, callback, paths.join(':'), SASS_OUTPUT_STYLE[style]);
};
exports.middleware = require('./lib/middleware');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment