Commit 3737754b by Steven Luscher

Implemented the imagePath option, for use with the image-url() function.

parent 1c3c5e63
......@@ -23,14 +23,19 @@ void WorkOnContext(uv_work_t* req) {
void extractOptions(_NAN_METHOD_ARGS, void* cptr, sass_context_wrapper* ctx_w, bool isFile) {
char *source;
char* pathOrData;
char* imagePath;
int output_style;
int source_comments;
String::AsciiValue astr(args[0]);
String::AsciiValue bstr(args[1]);
imagePath = new char[strlen(*bstr)+1];
strcpy(imagePath, *bstr);
if (ctx_w) {
// async (callback) style
Local<Function> callback = Local<Function>::Cast(args[1]);
Local<Function> errorCallback = Local<Function>::Cast(args[2]);
Local<Function> callback = Local<Function>::Cast(args[2]);
Local<Function> errorCallback = Local<Function>::Cast(args[3]);
if (isFile) {
ctx_w->fctx = (sass_file_context*) cptr;
} else {
......@@ -39,18 +44,18 @@ void extractOptions(_NAN_METHOD_ARGS, void* cptr, sass_context_wrapper* ctx_w, b
ctx_w->request.data = ctx_w;
ctx_w->callback = new NanCallback(callback);
ctx_w->errorCallback = new NanCallback(errorCallback);
output_style = args[4]->Int32Value();
source_comments = args[5]->Int32Value();
String::AsciiValue bstr(args[3]);
pathOrData = new char[strlen(*bstr)+1];
strcpy(pathOrData, *bstr);
output_style = args[5]->Int32Value();
source_comments = args[6]->Int32Value();
String::AsciiValue cstr(args[4]);
pathOrData = new char[strlen(*cstr)+1];
strcpy(pathOrData, *cstr);
} else {
// synchronous style
output_style = args[2]->Int32Value();
source_comments = args[3]->Int32Value();
String::AsciiValue bstr(args[1]);
pathOrData = new char[strlen(*bstr)+1];
strcpy(pathOrData, *bstr);
output_style = args[3]->Int32Value();
source_comments = args[4]->Int32Value();
String::AsciiValue cstr(args[2]);
pathOrData = new char[strlen(*cstr)+1];
strcpy(pathOrData, *cstr);
}
if (isFile) {
......@@ -58,21 +63,21 @@ void extractOptions(_NAN_METHOD_ARGS, void* cptr, sass_context_wrapper* ctx_w, b
char *filename = new char[strlen(*astr)+1];
strcpy(filename, *astr);
ctx->input_path = filename;
ctx->options.image_path = new char[0];
ctx->options.image_path = imagePath;
ctx->options.output_style = output_style;
ctx->options.source_comments = source_comments;
ctx->options.include_paths = pathOrData;
if (source_comments == SASS_SOURCE_COMMENTS_MAP) {
String::AsciiValue cstr(args[6]);
ctx->source_map_file = new char[strlen(*cstr)+1];
strcpy(ctx->source_map_file, *cstr);
String::AsciiValue dstr(args[7]);
ctx->source_map_file = new char[strlen(*dstr)+1];
strcpy(ctx->source_map_file, *dstr);
}
} else {
sass_context *ctx = (sass_context*)cptr;
source = new char[strlen(*astr)+1];
strcpy(source, *astr);
ctx->source_string = source;
ctx->options.image_path = new char[0];
ctx->options.image_path = imagePath;
ctx->options.output_style = output_style;
ctx->options.source_comments = source_comments;
ctx->options.include_paths = pathOrData;
......
......@@ -34,14 +34,16 @@ var SASS_SOURCE_COMMENTS = {
};
var prepareOptions = function(options) {
var paths, style, comments;
var paths, imagePath, style, comments;
options = typeof options !== 'object' ? {} : options;
paths = options.include_paths || options.includePaths || [];
imagePath = options.image_path || options.imagePath || '';
style = SASS_OUTPUT_STYLE[options.output_style || options.outputStyle] || 0;
comments = SASS_SOURCE_COMMENTS[options.source_comments || options.sourceComments] || 0;
return {
paths: paths,
imagePath: imagePath,
style: style,
comments: comments
};
......@@ -55,12 +57,12 @@ var deprecatedRender = function(css, callback, options) {
var oldCallback = function(css) {
callback(null, css);
};
return binding.render(css, oldCallback, errCallback, options.paths.join(':'), options.style, options.comments);
return binding.render(css, options.imagePath, oldCallback, errCallback, options.paths.join(':'), options.style, options.comments);
};
var deprecatedRenderSync = function(css, options) {
options = prepareOptions(options);
return binding.renderSync(css, options.paths.join(':'), options.style, options.comments);
return binding.renderSync(css, options.imagePath, options.paths.join(':'), options.style, options.comments);
};
exports.render = function(options) {
......@@ -74,11 +76,11 @@ exports.render = function(options) {
options.error = options.error || function(){};
if (options.file !== undefined && options.file !== null) {
return binding.renderFile(options.file, options.success, options.error, newOptions.paths.join(path.delimiter), newOptions.style, newOptions.comments, options.sourceMap);
return binding.renderFile(options.file, newOptions.imagePath, options.success, options.error, newOptions.paths.join(path.delimiter), newOptions.style, newOptions.comments, options.sourceMap);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
return binding.render(options.data, options.success, options.error, newOptions.paths.join(path.delimiter), newOptions.style);
return binding.render(options.data, newOptions.imagePath, options.success, options.error, newOptions.paths.join(path.delimiter), newOptions.style);
};
exports.renderSync = function(options) {
......@@ -91,11 +93,11 @@ exports.renderSync = function(options) {
newOptions = prepareOptions(options);
if (options.file !== undefined && options.file !== null) {
return binding.renderFileSync(options.file, newOptions.paths.join(path.delimiter), newOptions.style, newOptions.comments);
return binding.renderFileSync(options.file, newOptions.imagePath, newOptions.paths.join(path.delimiter), newOptions.style, newOptions.comments);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
return binding.renderSync(options.data, newOptions.paths.join(path.delimiter), newOptions.style);
return binding.renderSync(options.data, newOptions.imagePath, newOptions.paths.join(path.delimiter), newOptions.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