diff --git a/binding.gyp b/binding.gyp index 80b9e4c..d244064 100644 --- a/binding.gyp +++ b/binding.gyp @@ -31,6 +31,7 @@ 'src/libsass/sass2scss.cpp', 'src/libsass/sass_context.cpp', 'src/libsass/sass_functions.cpp', + 'src/libsass/sass_interface.cpp', 'src/libsass/sass_util.cpp', 'src/libsass/sass_values.cpp', 'src/libsass/source_map.cpp', diff --git a/bindings/win32-ia32/0.8.0/binding.node b/bindings/win32-ia32/0.8.0/binding.node deleted file mode 100644 index d915158..0000000 Binary files a/bindings/win32-ia32/0.8.0/binding.node and /dev/null differ diff --git a/bindings/win32-ia32/0.9.11/binding.node b/bindings/win32-ia32/0.9.11/binding.node deleted file mode 100644 index 2489fdd..0000000 Binary files a/bindings/win32-ia32/0.9.11/binding.node and /dev/null differ diff --git a/bindings/win32-ia32/0.9.3/binding.node b/bindings/win32-ia32/0.9.3/binding.node deleted file mode 100644 index 0942917..0000000 Binary files a/bindings/win32-ia32/0.9.3/binding.node and /dev/null differ diff --git a/bindings/win32-ia32/0.9.7/binding.node b/bindings/win32-ia32/0.9.7/binding.node deleted file mode 100644 index 1ae2b76..0000000 Binary files a/bindings/win32-ia32/0.9.7/binding.node and /dev/null differ diff --git a/bindings/win32-x64/0.10.2/binding.node b/bindings/win32-x64/0.10.2/binding.node new file mode 100644 index 0000000..11313b6 Binary files /dev/null and b/bindings/win32-x64/0.10.2/binding.node differ diff --git a/lib/binding.cpp b/lib/binding.cpp new file mode 100644 index 0000000..28b4df2 --- /dev/null +++ b/lib/binding.cpp @@ -0,0 +1,20 @@ +#include +#include +#include "./sync.h" + +using v8::FunctionTemplate; +using v8::Handle; +using v8::Object; +using v8::String; + +// Expose synchronous and asynchronous access to our +// Estimate() function +void InitAll(Handle exports) { + exports->Set(NanNew("renderSync"), + NanNew(RenderSync)->GetFunction()); + + exports->Set(NanNew("importedCallback"), + NanNew(importedCallback)->GetFunction()); +} + +NODE_MODULE(binding, InitAll) diff --git a/lib/index.js b/lib/index.js index 3a3983e..d7dafcc 100644 --- a/lib/index.js +++ b/lib/index.js @@ -175,9 +175,9 @@ function getOptions(options) { }; if (importer) { - options.importer = function(file, prev, key, v2) { + options.importer = function(file, prev, key) { var done = function(data) { - binding[v2 ? 'importedCallback2' : 'importedCallback']({ + binding.importedCallback({ index: key, objectLiteral: data }); diff --git a/lib/sync.cc b/lib/sync.cc index 59c3d71..d0b34d1 100644 --- a/lib/sync.cc +++ b/lib/sync.cc @@ -3,58 +3,58 @@ #include #include #include -#include "../libsass/sass_interface.h" - -using namespace v8; -using namespace std; -using namespace Sass; - -char* CreateString(Local value) { - size_t count; - return NanCString(value, &count); -} - -void prepareOptions(Local options, sass_context* ctx) { - ctx->source_string = CreateString(options->Get(NanNew("data"))); - ctx->options.image_path = CreateString(options->Get(NanNew("imagePath"))); - ctx->options.output_style = options->Get(NanNew("style"))->Int32Value(); - ctx->options.source_comments = options->Get(NanNew("comments"))->Int32Value(); - ctx->options.omit_source_map_url = options->Get(NanNew("omit_source_map_url"))->Int32Value(); - ctx->options.is_indented_syntax_src = options->Get(NanNew("is_indented_syntax_src"))->Int32Value(); - ctx->options.include_paths = CreateString(options->Get(NanNew("paths"))); - ctx->options.precision = options->Get(NanNew("precision"))->Int32Value(); - ctx->options.source_map_file = CreateString(options->Get(NanNew("source_map_file"))); -} +#include "../src/libsass/sass_interface.h" + +// using namespace v8; +// using namespace std; +// using namespace Sass; + +// char* CreateString(Local value) { +// size_t count; +// return NanCString(value, &count); +// } + +// void prepareOptions(Local options, sass_context* ctx) { +// ctx->source_string = CreateString(options->Get(NanNew("data"))); +// ctx->options.image_path = CreateString(options->Get(NanNew("imagePath"))); +// ctx->options.output_style = options->Get(NanNew("style"))->Int32Value(); +// ctx->options.source_comments = options->Get(NanNew("comments"))->Int32Value(); +// ctx->options.omit_source_map_url = options->Get(NanNew("omit_source_map_url"))->Int32Value(); +// ctx->options.is_indented_syntax_src = options->Get(NanNew("is_indented_syntax_src"))->Int32Value(); +// ctx->options.include_paths = CreateString(options->Get(NanNew("paths"))); +// ctx->options.precision = options->Get(NanNew("precision"))->Int32Value(); +// ctx->options.source_map_file = CreateString(options->Get(NanNew("source_map_file"))); +// } // Simple synchronous access to the `Estimate()` function NAN_METHOD(RenderSync) { NanScope(); - sass_context* ctx = sass_new_context(); + // sass_context* ctx = sass_new_context(); - prepareOptions(args[0]->ToObject(), ctx); + // prepareOptions(args[0]->ToObject(), ctx); - sass_compile(ctx); + // sass_compile(ctx); - if (ctx->error_status == 0) { - Local output = NanNew(ctx->output_string); - sass_free_context(ctx); - NanReturnValue(output); - } + // if (ctx->error_status == 0) { + // Local output = NanNew(ctx->output_string); + // sass_free_context(ctx); + // NanReturnValue(output); + // } - Local error = NanNew(ctx->error_message); - sass_free_context(ctx); - NanThrowError(error); + // Local error = NanNew(ctx->error_message); + // sass_free_context(ctx); + // NanThrowError(error); NanReturnUndefined(); } -NAN_METHOD(Sass2scss) { +NAN_METHOD(importedCallback) { NanScope(); - char *source = CreateString(args[0]); - char *converted = sass2scss(source, SASS2SCSS_PRETTIFY_1); - delete[] source; + // char *source = CreateString(args[0]); + // char *converted = sass2scss(source, SASS2SCSS_PRETTIFY_1); + // delete[] source; - Local output = Local::New(String::New(converted)); + // Local output = Local::New(String::New(converted)); NanReturnValue(output); -} \ No newline at end of file +} diff --git a/lib/sync.h b/lib/sync.h index 2efe90d..cec90f7 100644 --- a/lib/sync.h +++ b/lib/sync.h @@ -5,6 +5,6 @@ #include NAN_METHOD(RenderSync); -NAN_METHOD(Sass2scss); +NAN_METHOD(importedCallback); #endif // FIS_SASS_SYNC_H_ diff --git a/map.json b/map.json index 4d026c3..f47c346 100644 --- a/map.json +++ b/map.json @@ -1,16 +1,10 @@ { "win32-x64":[ - "0.8.0", - "0.9.3", - "0.9.7", - "0.9.11" + "0.10.2" ], "win32-ia32":[ - "0.8.0", - "0.9.3", - "0.9.7", - "0.9.11" + "0.10.2" ], "linux-x64": [ @@ -33,4 +27,4 @@ "0.9.7", "0.9.11" ] -} \ No newline at end of file +} diff --git a/src/binding.cpp b/src/binding.cpp index 977fd11..096a145 100644 --- a/src/binding.cpp +++ b/src/binding.cpp @@ -26,11 +26,10 @@ struct Sass_Import** sass_importer2(const char* file, const char* prev, void* co Handle argv[] = { NanNew(strdup(file ? strdup(file) : 0)), NanNew(strdup(prev ? strdup(prev) : 0)), - NanNew(imports_collection.size() - 1), - NanNew(1) + NanNew(imports_collection.size() - 1) }; - NanNew(ctx_w->importer_callback->Call(4, argv)); + NanNew(ctx_w->importer_callback->Call(3, argv)); if (try_catch.HasCaught()) { node::FatalException(try_catch); @@ -159,7 +158,7 @@ NAN_METHOD(RenderSync) { NanReturnValue(NanNew(result == 0)); } -NAN_METHOD(ImportedCallback2) { +NAN_METHOD(ImportedCallback) { NanScope(); TryCatch try_catch; @@ -214,7 +213,7 @@ NAN_METHOD(ImportedCallback2) { void RegisterModule(v8::Handle target) { NODE_SET_METHOD(target, "renderSync", RenderSync); - NODE_SET_METHOD(target, "importedCallback2", ImportedCallback2); + NODE_SET_METHOD(target, "importedCallback", ImportedCallback); } NODE_MODULE(binding, RegisterModule); diff --git a/test.js b/test.js index 84a9b92..93260a2 100644 --- a/test.js +++ b/test.js @@ -11,3 +11,21 @@ if ( !ret.css.match( expect ) ) { } else { console.log( 'Simple test passed!'); } + + +var ret = sass.renderSync({ + file: 'aaa.scss', + data: '@import "xxx";\n'+source, + importer: function(url, pre, done) { + return { + contents: "body{color: red}" + } + } +}); + +if ( !~ret.css.indexOf('color: white;') ) { + throw new Error( 'Some thing wrong.' ); +} else { + console.log( 'importer is supported'); +} +