the e() LESS function

used to escape strings in values.
Added Anonymous node to handle things like this.
This commit is contained in:
cloudhead
2010-04-22 19:42:02 -04:00
parent e46e71a4d1
commit 904d997730
5 changed files with 22 additions and 1 deletions

View File

@@ -40,7 +40,7 @@ var less = {
'keyword', 'variable', 'ruleset', 'element',
'selector', 'quoted', 'expression', 'rule',
'call', 'url', 'alpha', 'import',
'mixin', 'comment'
'mixin', 'comment', 'anonymous'
].forEach(function (n) {
require(path.join('less', 'tree', n));
});

View File

@@ -28,6 +28,9 @@ tree.functions = {
else if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
else return m1;
}
},
e: function (str) {
return new(tree.Anonymous)(str);
}
};

View File

@@ -0,0 +1,11 @@
if (typeof(require) !== 'undefined') { var tree = require('less/tree') }
tree.Anonymous = function Anonymous(string) {
this.value = string.content;
};
tree.Anonymous.prototype = {
toCSS: function () {
return this.value;
},
eval: function () { return this }
};

View File

@@ -4,3 +4,6 @@
height: undefined("self");
border-width: 5;
}
#built-in {
escaped: -Some::weird(#thing, y);
}

View File

@@ -4,3 +4,7 @@
height: undefined("self");
border-width: add(2, 3);
}
#built-in {
escaped: e("-Some::weird(#thing, y)");
}