Skip to content

mixin definitions inside mixin definitions #73

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

Closed
jamesfoster opened this issue Jul 9, 2010 · 1 comment
Closed

mixin definitions inside mixin definitions #73

jamesfoster opened this issue Jul 9, 2010 · 1 comment

Comments

@jamesfoster
Copy link
Contributor

Allow a mixin.Definition inside a mixin.Definition:

.apples(@width: 100px) {
  .bananas() {
    width: @width;
  }
}

.apples(50px);

#test {
  .bananas();
}

calling .apples() effectively "unlocks" the inner mixins.

This is great for encapsulating mixins/variables for libraries.

@SomMeri
Copy link
Member

SomMeri commented Mar 30, 2013

Less.js 1.3.3 already has this feature, unit test is inside scope.less test file starting at line 53. I also tested fruits example from this issue and it compiles into:

#test {
  width: 50px;
}

I tried also to import mixin into a namespace and that case works too:

.apples(@width: 100px) { .bananas() { width: @width; } }

#namespace {
  .apples(700px);
}

#test {
  #namespace > .bananas();
}

The only possible problem with this feature is that it is not really declarative, e.g. unlocking must be done before using the imported mixin. This will throw syntax error:

.apples(@width: 100px) {
  .bananas() {
     width: @width;
  }
}

#test {
  .bananas(); // syntax error
}

.apples(50px);

If the last point was intentional, then this can probably be closed.

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

No branches or pull requests

3 participants