Skip to content
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

Using a generated mixin #2749

Closed
palsan opened this issue Dec 3, 2015 · 2 comments
Closed

Using a generated mixin #2749

palsan opened this issue Dec 3, 2015 · 2 comments

Comments

@palsan
Copy link

palsan commented Dec 3, 2015

Hello friends!

I experience problems including the mixin that was loop-generated:

/* automatic generator for simple single parameter classes */

.generate-numeric-param1( @class-name; @param; @max; @min: 0; @step: 1pc; @current: 0) when (@current =< @max) {
  .@{class-name}@{current} {
    @{param}: (1px * @current);
  }
  .generate-numeric-param1( @class-name; @param; @max; @min; @step; @current + @step);
}

/* generate ".marN" classes where N = 0,5,10,15,...50 
 *
 * .mar0 { margin: 0px; }
 * .mar5 { margin: 5px; } 
 * .mar10 { margin: 10px; }
 * ...
 * 
 * */

.generate-numeric-param1(mar,margin,50,@step:5);


/* try to use generated margin classes */

.use-generated-mar5 {
  .mar5(); /* can use this */
}

.use-generated-mar0 {
  .mar0(); /* cannot use this - error: NameError: .mar0 is undefined */
}

Using .mar0(); works, if I define in manually like so

.mar0 { margin: 0px; }

My less is:

lessc -v
lessc 2.5.3 (Less Compiler) [JavaScript]

@SomMeri
Copy link
Member

SomMeri commented Dec 3, 2015

It is not currently possible to generate mixins on the fly. There is long discussion about the topic in the Use Dynamically Generated Classes as Mixins #1399 issue - there are some difficulties in defining how exactly it should work.

I will close this as duplicate, but feel free to add to discussion in there.

@SomMeri SomMeri closed this as completed Dec 3, 2015
@seven-phases-max
Copy link
Member

Aside of #1399, the use-case itself is actually an XY-problem.
The right solution to the use-case is as easy as a parametric mixin, i.e.:

.mar(@value) {
    margin: @value * 1px;    
}

.use-mar5 {
  .mar(5);
}

.use-mar0 {
  .mar(0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
@SomMeri @palsan @seven-phases-max and others