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

Commit

Permalink
~interim commit~custom importers~
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Mar 22, 2015
1 parent 8c641f4 commit 5211c5d
Show file tree
Hide file tree
Showing 33 changed files with 1,465 additions and 182 deletions.
15 changes: 14 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
'target_name': 'binding',
'sources': [
'src/binding.cpp',
'src/sass_context_wrapper.cpp'
'src/create_string.cpp',
'src/custom_function_bridge.cpp',
'src/custom_importer_bridge.cpp',
'src/sass_context_wrapper.cpp',
'src/sass_types/boolean.cpp',
'src/sass_types/color.cpp',
'src/sass_types/error.cpp',
'src/sass_types/factory.cpp',
'src/sass_types/list.cpp',
'src/sass_types/map.cpp',
'src/sass_types/null.cpp',
'src/sass_types/number.cpp',
'src/sass_types/string.cpp',
'src/sass_types/value.cpp'
],
'include_dirs': [
'<!(node -e "require(\'nan\')")',
Expand Down
34 changes: 27 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ require('./extensions');

var binding = require(process.sass.getBinaryPath(true));

// Expose sass types
module.exports.types = binding.types;

/**
* Get input file
*
Expand Down Expand Up @@ -172,13 +175,9 @@ module.exports.render = function(options, cb) {
var importer = options.importer;

if (importer) {
options.importer = function(file, prev, key) {
options.importer = function(file, prev, bridge) {
function done(data) {
console.log(data); // ugly hack
binding.importedCallback({
index: key,
objectLiteral: data
});
bridge.success(data);
}

var result = importer.call(options.context, file, prev, done);
Expand All @@ -189,6 +188,27 @@ module.exports.render = function(options, cb) {
};
}

if (options.functions) {
Object.keys(options.functions).forEach(function(signature) {
var callback = options.functions[signature];

options.functions[signature] = function() {
var args = Array.prototype.slice.call(arguments),
bridge = args.pop();

function done(data) {
bridge.success(data);
}

var result = callback.apply(this, args.concat(done));

if (result) {
done(result);
}
};
});
}

options.data ? binding.render(options) : binding.renderFile(options);
};

Expand All @@ -206,7 +226,7 @@ module.exports.renderSync = function(options) {

if (importer) {
options.importer = function(file, prev) {
return { objectLiteral: importer.call(options.context, file, prev) };
return importer.call(options.context, file, prev);
};
}

Expand Down
Loading

0 comments on commit 5211c5d

Please sign in to comment.