-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
plugin-ins functions #129
Comments
Actually you should just be able to add it directly, after including
Try it, it should work. |
Well, i don't know why, but it doesn't work, the output is still "rgbstr(#ccc)". less.tree.functions.rgbstr = function (color) { |
Same here. Any tips? |
The line // [1] Defines Quoted attributes; note the params
tree.Quoted = function (str, content, escaped, i) {
this.escaped = escaped;
this.value = content || '';
this.quote = str.charAt(0);
this.index = i;
};
// [2] Quoted.toCSS();
tree.Quoted.prototype = {
toCSS: function () {
...
},
// [3] Build me this biznass when no method/attribute is called
eval: function (env) {
...
// [4] Here's what you returned
return new(tree.Quoted)(this.quote + value + this.quote, value, this.escaped, this.index);
}
}; Take this dummy mockup: less.tree.functions.rgbstr = function (color) {var str = color; return new(less.tree.Quoted)('"' + str + '"', str,true,1);}; Calling {
"escaped": true,
"eval": function (b) {
var c = this,
d = this.value.replace(/`([^`]+)`/g, function (d, e) {
return (new a.JavaScript(e, c.index, !0)).eval(b).value
}).replace(/@\{([\w-]+)\}/g, function (d, e) {
var f = (new a.Variable("@" + e, c.index)).eval(b);
return "value" in f ? f.value : f.toCSS()
});
return new a.Quoted(this.quote + d + this.quote, d, this.escaped, this.index)
},
"index": 1,
"quote": "\"",
"toCSS": function () {
return this.escaped ? this.value : this.quote + this.value + this.quote
},
"value": "hotpink"
} Just ask for what you want and its yours: |
Might be nice to put this on the wiki? |
Absolutely. The more we could document about the inner workings of the LESS parser, the easier it would be for other JS developers to contribute patches. The ability to do this was news to me until you labeled it. |
Is it possible to pass some kind of "extra" object into less during parsing stage that could be used then by function? I want to have a helper |
more info is now on the homepage - setting less.functions before including less will include those functions into less. would be nice to add an example, will add this request to lesscss.org - less/old-lesscss.org#54 |
Hi,
It's not really a problem but it was the only place I found to ask...
I was wondering if there's a nice way to "plugin" new functions into the less.js "tree.functions" ?
For the moment i've hacked into the source, not very nice...
For the record, i need a rgbstr (Color => RGB String) function to make a bg_image_gradient mixin,
something like this:
.bgimggrad (@startcolor: #ccc, @Stopcolor: #ccc, @SiZe: 50) {
background: @Stopcolor e(%("url('/images/grad/%s/%s/%s')",rgbstr(@startcolor),rgbstr(@Stopcolor),@SiZe)) 0 0 repeat-x;
}
that returns this:
background: #ccc url("/images/grad/204,204,204/204,204,204/50") 0 0 repeat-x;
to use with a dynamic gradient generator like this one: http://djangosnippets.org/snippets/787/
Guillaume
The text was updated successfully, but these errors were encountered: