These are chat archives for less/less.js

27th
Apr 2017
Strider
@StreetStrider
Apr 27 2017 19:35
Hello. I'm trying to define a custom function and supply it to engine with plugins. My function seems to work in simple case, but fails when I try to use function inside other function, like url(my-function('some-val')). Parser is going crazy about parens, I got error: expected ')' got '('. What I'm doing wrong? Supplying function result to other function is a common case and it works ok with standard LESS functions and even with CSS "functions" (like url).
Strider
@StreetStrider
Apr 27 2017 19:52
Looks like it's not possible to use function inside url, I should defer to visitors instead..
Calvin Juárez
@calvinjuarez
Apr 27 2017 20:45
@StreetStrider If you're looking to just ouput the CSS url() function, you can escape it w/ e(). So, like, e('url(@{stuff-to-wrap-in-url})')
Matthew Dean
@matthew-dean
Apr 27 2017 20:45
A url() is not a function. So no, I don't think anyone has ever tried to do that. However, you could assign the result of a function to a variable, and you can use a variable inside url()
Calvin Juárez
@calvinjuarez
Apr 27 2017 20:46
There are a few examples of ways to put the output of a function into url() at https://github.com/less/less.js/issues/3044#issuecomment-295534079
Hopefully that helps.
Matt Scheurich
@lvl99
Apr 27 2017 20:50
~"url("my-function('some-val')~")" could work too
Strider
@StreetStrider
Apr 27 2017 21:56
Thanks for the tips. All of the solutions is a combination of escaping magic. I'm thinking, in my case, visitors is a good alternative, since I need to apply special logic to some urls exclusively. And since I'm already in plugin land, it is not too harder to implement a visitor instead of custom function.
@matthew-dean I thought about it too but this will require to introduce one new variable for every url.
Thanks for help.