-
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
Support strings as property names #698
Conversation
Example: @Property: "border-radius"; ~"-webkit-@{property}": 5px;
Should be closed? My understanding is that 1.3 added this feature? |
This is the commit 93b23d2 that added it and referenced in my updated blog post. |
Nope, 93b23d2 added support for selectors However @cloudhead made it clear that he doesn't like 93b23d2 to begin with (being too much a preprocessing feature and breaking the language design). Thus I expect him not to merge this pull-request and rather reject/close it. In the end that depends on which direction less.js will take with 1.4. |
Wow :( |
That's a shame. A perfect use case would be .selector { CSS - .selector { |
I didn't know I could be used as a unit... This looks cool, though. :-) |
If features like this don't make it into the core, isn't it only a matter of time someone forks it with the intent of allowing all preprocessor features? |
I like it ... thumbs up sirlantis |
This would/will solve this problem using IMO a more in keeping syntax => #790 |
I've made a set of mixins to workaround this issue: https://github.com/borodean/less-properties It works like this: @property: border-radius;
.class {
.property(@property, 10px);
} Which will output in: .class {
-less-property: property;
border-radius: 10px;
} Or even this: .class {
.property(border-radius, 10px, 'moz webkit o');
} Which outputs in: .class {
-less-property: property;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
-o-border-radius: 10px;
} I would appreciate any help for developing this set further. |
+1 |
1 similar comment
+1 |
Either this or #790 would help LESS to be more DRY. Even Twitter Bootstrap is stuck repeating itself over and over because there is just simply no decent way to do what needs to be done:
I believe that this is one of the language features that is holding LESS back from having a complete set of CSS3 mixins like Compass. |
@sashasklar @cloudhead Could you add an opinion on this issue? Is that something that you object to have in LESS? I understand your concert that this adds a macro-like mechanism to the language, however it's use is restricted and useful (see examples from above). |
Although a nice idea this shouldn't be implemented because adding prefixes carte blanche will add bloat to your code. Not every CSS3 element has had all the prefixes all the time. So adding them all to something would be a bad thing to do. |
@sturobson This pull-request only allows the Whether or not to add and an |
Personally the syntax is ugly with this fix. #790 will be alot easier to follow imo |
no it doesn't. read it carefully. it is exactly the same as php's variable variable syntax. This is for having variable property names, not variable values. |
#790 is about writing dynamically to a variable through another variable (variable variable names). The PHP equivalent:
|
you can do the same thing. I've tried it. I will write a use case to show an example |
I was looking for a feature like that and hope it will be implemented soon. Would save a lot of time just being able to use the following instead of declaring mixins for every single CSS3 property:
|
I agree that this is pointing to a real problem: Having to repeat prefixes. Is this the most elegant solution? Not sure. It is a solution, but the escaped string syntax always looks messy to me. In addition, prefixing often looks similar, but not all prefixes are needed in every case. Some things get finalized (non-prefixed) in a browser before others, meaning that you would have to override / add prefixes in specific cases anyway.... meaning abstracting a "prefixing" function doesn't really make sense. So.... |
Assuming I get my pull request to have selectors like this
then the obvious extension is to use this for property names
in dotless I was thinking of writing a plugin that replaced all property names ending in -all-browsers with duplicates for every browser prefix. e.g.
becomes
etc. So another question.. what uses does prefix interpolation have outside of prefixing of browser properties? |
alternate idea for prefixes only remaining case is this
==>
which I'm not sure I like.. its a good abstraction, but yeh, not sure about it. |
Here's my solution to this problem: vendorify.less. It was inspired by @borodean's solution, but from his test cases noticed it had a bug. For example, you can't pass in values with spaces nor does it support comma-separated compound values - which would be needed for things such as multiple backgrounds, and gradients, etc.) When I started going through his code to find a fix, I created what I think is a more simple solution to the same idea. Sure, it won't allow you to change which vendor prefixes get used (unless you modify the actual mixin), but how often do you need to specify different vendor prefixes within the same project? Checkout the test cases in the comments below my vendorify.less Gist. It is quite extensive allowing you to specify values with spaces: /* LESS */
.style {
.vendorify(border-radius, 5px 10px);
}
/* CSS Output */
.style {
-less-vendorify: ;
-o-border-radius: 5px 10px;
-ms-border-radius: 5px 10px;
-moz-border-radius: 5px 10px;
-webkit-border-radius: 5px 10px;
border-radius: 5px 10px;
} and even compound values: /* LESS */
.style {
.vendorify(background, url(bg2.png) repeat, url(bg3.png) no-repeat);
}
/* CSS Output */
.style {
-less-vendorify: ;
-o-background: url(bg2.png) repeat, url(bg3.png) no-repeat;
-ms-background: url(bg2.png) repeat, url(bg3.png) no-repeat;
-moz-background: url(bg2.png) repeat, url(bg3.png) no-repeat;
-webkit-background: url(bg2.png) repeat, url(bg3.png) no-repeat;
background: url(bg2.png) repeat, url(bg3.png) no-repeat;
} |
It's a good question. If it has none, then, like other similar issues, the syntax and problem should be focused on just the most elegant solution for that. But.... I could see someone doing this?
Seems weird, but rather than the theoretical, it's worth input on that point. Are people wanting this only for prefixes? |
I've said this several times, the CSS spec is introducing custom properties, variable property names is a must-have that should be high on or priority list. Vendor prefixes is a convenient example (and not very compelling), but it's not the only use for custom properties. |
Right. Even if it was only for prefixes, it still seems valuable to let the stylesheet author swap in property names. It seems like an intuitive addition. Let's do this, based on @lukeapage's syntax. |
Which one? He's mentioned a couple, you probably mean |
Yes (to the first point). This seems like an easy win:
|
Agreed. Variable interpolation within property names is a no-brainer. +1 for the |
Maybe this is implied, but to be clear the syntax should allow the entire property name to be interpolated: @{prop}: value And since values can already be variables: @{prop}: @value; |
Again, agreed. There are plenty of situations where this would be handy, and just as many places it would be critical to work with mixins. |
Agreed. I think we don't take that for granted as often as we should. |
+1 |
+1 Any way to write a generic and clean .vendorize is required - I actually don't care which. I want something that allows me to generate vendor prefixes without the repetition, and allows me to override specific vendor names if they differ. |
+1 for the awesome power of:
|
+1 for this,
This basically renders an extra property called qwerty which is ignored by the browser. |
👍 would be awesome if this gets merged. |
Yeah, I doubt anybody wants to rush it into an already jam-packed 1.5 release, but if it can be done, that would be fantastic. |
a great feature for making right to left pages from left to right ones... 👍 |
later pull request merged. |
This is analogous to the recent 93b23d2 (support strings as selectors) commit.
Includes a regression test.
This fixes #36 and should make creating vendor-aware libraries/mixins much easier. An example where this could be useful:
Also it should make @metaskills (see blogpost) happy. 🎁