-
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
Added support for default variables #1104
Conversation
You can now define default variables via `@var: 1px !default;`. It will behave as `@var: 1px;` if `@var` hasnt't been defined yet. Otherwise it will be ignored. This is useful for frameworks (e.g. Bootstrap) which need to define variables to work but want to allow the user of the framework to change them without messing with the internal less-stylesheets.
Nice to see you back, your unit and media bubbling work is great. at the moment people have to put a variables file last and those definitions override earlier ones.. this would require bootstrap to put !default after every variable definition and would mean people could override a variable by putting it first.. could you go into the benefits and the scenario that requires this more? |
Hi Luke, sorry for not making it clearer in the original pull-request (wrote it just before going to bed). @Warry did a better job in #313. So another try: I wrote a small CSS-framework for some of my private/freelance projects. I'm using Bootstrap as an example because it is public and has a similar (near identical) structure to mine and I think it also could benefit from the When you do Now for example you want to change Add variable after bootstrap
Cons: Doesn't affect bootstrap. Do it "the way it's supposed to be done"
Cons: This makes updating to a newer Bootstrap difficult. You need to extract your local changes of Define your own
|
I'm just surprised the "Add variable after bootstrap" case doesn't work. I wonder if its because the import is evaluated before being mixed into the main less file and getting the overriding variable |
Now I need an emoticon for a facepalm. Seems to be an issue of the node.js Framework I am using... just tested it with a clean less and of course it worked. |
Sorry again for wasting my time and yours. I hope to get back at less.js with a quality pull-request next time. ;) |
that is pretty strange if it's the node.js framework.. It could be a timing issue or a bug.. It took some debate to agree that the last definition should be used, not the last before the current rule's definition.. and there are some up and down sides to it. If it is changed then this would definitely be needed. |
You can now define default variables via
@var: 1px !default;
. It willbehave as
@var: 1px;
if@var
hasnt't been defined yet. Otherwiseit will be ignored.
This is useful for frameworks (e.g. Bootstrap) which need to define
variables to work but want to allow the user of the framework to
change them without messing with the internal less-stylesheets.
Sass has this feature and it is used in the SASS-fork of Bootstrap and comes in quite handy.
This pull-request is based on #313 but with a test and the changes moved to the right places.