Skip to content

Commit

Permalink
Added support of any number of arguments in context helpers and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Jul 29, 2013
1 parent d015ea0 commit b03443f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@ npm-debug.log

tmp/
doc/
.idea
11 changes: 5 additions & 6 deletions lib/mincer/engines/less_engine.js
Expand Up @@ -162,15 +162,14 @@ LessEngine.prototype.evaluate = function (context, locals) {
var error = null,
result = null;

var fixedLocals = {};
Object.keys(locals).forEach(function(local) {
fixedLocals[local] = function(lessArg) {
return new less.tree.Anonymous(locals[local](lessArg.value));
_.forEach(locals, function(localFunc, localName) {
less.tree.functions[localName] = function() {
var extractedLessArguments = _.map(arguments, 'value');

return new less.tree.Anonymous(localFunc.apply(undefined, extractedLessArguments));
};
});

_.extend(less.tree.functions, fixedLocals);

var parser = new (less.Parser)({
paths: [path.dirname(this.file)].concat(context.environment.paths),
optimization: 1,
Expand Down
9 changes: 9 additions & 0 deletions test/engines_test.js
Expand Up @@ -25,4 +25,13 @@ describe("Engines", function () {
});
});

describe("LESS", function () {

it("should support context helpers", function () {
var asset = env.findAsset("less_engine/stylesheet");
assert(asset.toString().match(/\/assets\/ixti-[a-f0-9]{32}.gif/));
assert(asset.toString().match(/data:image\/gif;base64/));
});
});

});
6 changes: 6 additions & 0 deletions test/fixtures/less_engine/stylesheet.css.less
@@ -0,0 +1,6 @@
@var: asset_path("ixti.gif");
@dataUri: asset_data_uri("ixti.gif");

.class:before { content: @var; }
.class2 { background-image: @dataUri; }

0 comments on commit b03443f

Please sign in to comment.