New % function, to perform string interpolation

This commit is contained in:
cloudhead
2010-04-30 14:06:36 -04:00
parent f3e28e08bf
commit d75becf9ba
2 changed files with 11 additions and 1 deletions

View File

@@ -67,6 +67,16 @@ tree.functions = {
},
e: function (str) {
return new(tree.Anonymous)(str);
},
'%': function (quoted /* arg, arg, ...*/) {
var args = Array.prototype.slice.call(arguments, 1),
str = quoted.content;
for (var i = 0; i < args.length; i++) {
str = str.replace(/%[sd]/, args[i].toCSS());
}
str = str.replace(/%%/g, '%');
return new(tree.Quoted)('"' + str + '"', str);
}
};

View File

@@ -364,7 +364,7 @@ less.Parser = function Parser(env) {
call: function () {
var name, args;
if (! (name = $(/([a-zA-Z0-9_-]+)\(/g))) return;
if (! (name = $(/([a-zA-Z0-9_-]+|%)\(/g))) return;
if (name[1].toLowerCase() === 'alpha') { return $(this.alpha) }