-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
mixins and namespaces #57
Comments
Would it be possible to limit a mixin call or variable to the current namespace? something like:
where That way you could write a completely self contained namespace which isn't affected by naming conflicts outside that namespace. |
Hmm, well I guess mixins should be scoped like variables, so your first example should just work. |
But you would still include mixins with the sane name outside that scope.
This would output:
It would nice to able to make it self contained. |
In that case I think I would just specify the full path:
The other solution is to have self-contained modules like in less.rb. Eventually I guess something like |
yeah i thought about |
i just noticed that this is also an issue with variables
it thinks |
Right, because mixins aren't closures. |
Just so I know, do you consider this a bug worth fixing? If you like I can work on a fix and you can take it to fix less.js I prefer to leave these fundamental decisions up to you so we don't diverge too much. |
I think closures are good, so yea, ideally mixins would behave that way—I just don't have the time to look into it. It might actually be really easy, ie just appending the definition's frames to the caller, when evaluating the mixin. |
so does a mixin requires 2 frames to be evaluated properly? take the following example.
obviously, this fix would find the I've got an idea for deriving the mixin.Definition frame... lets say the mixin.Call is at start with the current frame, and pop rulesets as you go up. and push rulesets as you find matches. so effectively you would pop one issue with this is |
ok. here's a rudimentary fix I simply build a path to the matching rulesets in Ruleset.Find and then add that onto the context for resolving the mixin. It possibly doesn't behave as you'd expect under the more complex situations but it works for this simple one. |
I just pushed a really simple fix which makes mixins behave like closures. The only case in which it doesn't work is when mixins are defined after mixin calls, but that's not a good idea anyway. http://github.com/cloudhead/less.js/commit/04d2d3ab68af05c9c00e45418931236f315be416 |
I hate the javascript functions slice and splice, i always have to look them up. love how You didn't answer my earlier questions:
From looking at your change, I'm guessing the answers are "yes" and "10px"? I think your change is possibly too simple. Even, as you say, for the simple case of defining the mixin after the call. Variables are late bound, so should mixins be. Also, storing the frames on a mixin.Definition won't work for us since we allow a mixin.Definition inside a mixin.Definition:
... We don't know the frame of the This is great for encapsulating mixins/variables for libraries. Lets assume you had a grid system with a default width of 960px, 16 columns with a margin of 10px. you could call
and accept the defaults or call
and those would become the width, columns, and margin. you could then use the inner mixins like However, these are technically different issues and this issue should be closed? |
I'll close this and open another |
I'm trying to use a namespace to avoid naming conflicts as follows:
within the namespace
#ns
mixins should be able to reference each other.however, you get ".square is undefined"
The text was updated successfully, but these errors were encountered: