-
Notifications
You must be signed in to change notification settings - Fork 48
a example on user functions #54
Comments
Anything new on this side? less = {
functions: {
pxToRem: function (value, context) {
var dimensionObj = less.tree.functions.unit({
value: value
});
return (dimensionObj.value / context) + "rem";
}
}
}; It is copied to Also, could someone explain me how to use the native functions from a user function? |
this should be equal to less.tree.functions.. why doesn't If you look at the source code https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js#L229 the unit function accepts a value node and a unit (string). Your problem might be because of casing. Try renaming it let us know if you get success. |
@lukeapage thanks for the reply. Regarding the
And it make sense, infact
|
are you in browser or node? |
Browser, less 1.4.0 beta |
our unit tests test this works.. (and they pass) https://github.com/cloudhead/less.js/blob/master/test/browser/runner-main.js#L1 are you setting less before including the script (assume so otherwise it wouldn't be copied to the tree). I can only suggest you debug and work out why it isn't finding your function. put a breakpoint here https://github.com/cloudhead/less.js/blob/master/lib/less/tree/call.js#L35 |
p.s. did you set for function definition to lowercase or just the call or both? Its the definition that is important. |
Prepare the facepalm emoticon... there was a typo in the function name. here is my working function:
Anything I could have done better? |
it should be documented, you are right. context might be a number, but it also might be a dimension, so you would need to do |
+1 for the dimension thing.
instead? |
yes... depends how properly you want to do things. the function file is a good place to work out what less does getting a number from an argument... https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js#L505 using defaults... https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js#L236 |
and how to add to node?
less/less.js#129
The text was updated successfully, but these errors were encountered: