You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I could ask that of any unknown mixin, but SASS manages it fine.
I'd imagine a crude way of doing it is to reprocess the processed code if there are any mixins, or to add generated css rules to the list of things that can be included and it can go back and fill in any blanks. Even if you couldn't define parameters and they were non-parametric, the ability to do this and use this would be handy, and it makes sense intuitively that you'd be able to use mixins that were constructed via string interpolation after they've been created.
There are 2 levels really of it, there's full mixins with args, but then there's also just treating them as generated CSS rules to be included without args
(not sure why? - guess it could be something else stopping it, but I think that is it - I can see the following failing
@{a}-b {
}
as it will translate into 2 elements, where as
.a-b();
is a single element.. but it doesn't work even if you have
@a:~".a";
@{a}
maybe because it compares values and the value in the interpolated mixin selector is quoted ?
I am not sure how I would fix that.. you could add a falback that if it fails on element lookup it just does toCSS on both and compares that - it isn't very performant though - maybe selectors should cache the toCSS if they don't already.
So anyway, I think the above is the main problem.
A sub problem is that if you define interpolated selectors in the same scope as the mixin call, I think the mixin call is evaluated before the selector is eval'd - but thats what I meant when I said you could fix it for mixin calls or imports defining selectors using interpolation as long as it wasn't within the same scope. I'm not sure if we could fix that.
If you'd like to have a go at fixing it then please submit a pull request and if you find anything you aren't sure about just discuss it first.
We are working on extends and once that is finished, it should match interpolated selectors too.
I will close this since it is supported now (Less 1.6.x, by #1624). And more advanced "interpolated mixin" examples/use-cases/issues to be fixed/improved are in #1399.
Btw. the example in the first post has a typo (duplicated -) so here's corrected example (I also removed redudand ~""):
Activity
lukeapage commentedon Feb 21, 2013
if "laptop-" is unknown and has to be in a variable, how come the caller knows the mixin exists?
tomjn commentedon Feb 22, 2013
I could ask that of any unknown mixin, but SASS manages it fine.
I'd imagine a crude way of doing it is to reprocess the processed code if there are any mixins, or to add generated css rules to the list of things that can be included and it can go back and fill in any blanks. Even if you couldn't define parameters and they were non-parametric, the ability to do this and use this would be handy, and it makes sense intuitively that you'd be able to use mixins that were constructed via string interpolation after they've been created.
tomjn commentedon Feb 22, 2013
I requested this because I created a port of csswizardry-grids from SASS to LESS here:
https://github.com/Tarendai/csswizardry-grids.less
But right now you can't use the classes in your LESS code, only in the html markup, else compiles fail
lukeapage commentedon Feb 22, 2013
I see...
It would be nice to at least make it work for these cases.. e.g. classes returned from mixins, where the interpolation has already occurred
tomjn commentedon Feb 22, 2013
There are 2 levels really of it, there's full mixins with args, but then there's also just treating them as generated CSS rules to be included without args
tomjn commentedon Feb 22, 2013
How much work would this be and what would be the 'method' of implementing it?
lukeapage commentedon Feb 22, 2013
an interpolated selector ends up being eval'd here
https://github.com/cloudhead/less.js/blob/master/lib/less/tree/selector.js#L29
the trouble is that it then isn't getting a positive match here
https://github.com/cloudhead/less.js/blob/master/lib/less/tree/selector.js#L8
(not sure why? - guess it could be something else stopping it, but I think that is it - I can see the following failing
as it will translate into 2 elements, where as
is a single element.. but it doesn't work even if you have
maybe because it compares values and the value in the interpolated mixin selector is quoted ?
I am not sure how I would fix that.. you could add a falback that if it fails on element lookup it just does toCSS on both and compares that - it isn't very performant though - maybe selectors should cache the toCSS if they don't already.
So anyway, I think the above is the main problem.
A sub problem is that if you define interpolated selectors in the same scope as the mixin call, I think the mixin call is evaluated before the selector is eval'd - but thats what I meant when I said you could fix it for mixin calls or imports defining selectors using interpolation as long as it wasn't within the same scope. I'm not sure if we could fix that.
If you'd like to have a go at fixing it then please submit a pull request and if you find anything you aren't sure about just discuss it first.
We are working on extends and once that is finished, it should match interpolated selectors too.
glasserc commentedon May 28, 2013
It would also be nice to be able to invoke an interpolated mixin, as in #1338.
matthew-dean commentedon May 28, 2013
+1 to variable use in mixin definition and call
pauldijou commentedon Jun 2, 2013
Big +1 for both mixin interpolation and interpolated mixin!
seven-phases-max commentedon Feb 1, 2014
I will close this since it is supported now (Less 1.6.x, by #1624). And more advanced "interpolated mixin" examples/use-cases/issues to be fixed/improved are in #1399.
Btw. the example in the first post has a typo (duplicated
-) so here's corrected example (I also removed redudand~""):mhawk0 commentedon Apr 13, 2015
I am afraid that calling a mixin with interpolated variable, e.g.
is still not supported yet?
seven-phases-max commentedon Apr 13, 2015
No. Neither in interpolated nor in simple variable form. (I re-opened #1338).