-
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
add the any and deep keywords for extending, see issue #2101 #2506
Conversation
I'm not 100% sure but it looks like
this:
should result in:
I.e. P.S. Although rereading it once more it looks like my interpretation also conflict with
if |
@seven-phases-max In short, Your output demonstrates a flaw in the way the keyword is described, because while it doesn't technically extend the nesting under .mother, it does in actuality, because it represents a partial match on the next selector. So, if it behaved exactly as written, it wouldn't be a "shallow" nesting, because of the greedy matching on all child trees. The reason for this discrepancy I think is in some of the disagreement of what and where a selector was being matched. So the write-up for So that said, the intended output is probably more like this.
It would have effectively matched the middle segment, but not continued to match the descendants. And because it extends I had another look at the PR, and as far as I can tell, @bassjobsen's interpretation matches the (granted, very ambiguous) spec. More importantly, it does selector matching like The output for Correct me if I'm wrong in how |
|
@seven-phases-max Do you think there's a better keyword? Or a better way to describe it? |
|
Or call them according their implementation, before (any) and after (deep). Then not any or deep is the default and both any and deep = all. Then we also have the exclamation point or Capitalizing of the keyword. Personally i think exclamation point is the most clear solution. |
Before and after are way too easily confused with the CSS pseudo elements. And I don't see how it conceptually matches what's happening. So that doesn't seem like a better choice.
I agree, and it's the more "CSS-y" of the two. CSS as a rule doesn't use capitalization at all, and many CSS authors are allergic to it, so it's almost an "anti-CSS" pattern. Whereas CSS has exactly one flag syntax, which is the exclamation point. That said, I don't see any reason why keywords can't be case insensitive, AND have the optional flag syntax. Best of both worlds? |
(Y) I'll let people decide on names before I merge this. I was surprised the implementation is that simple - I've forgotten alot of it by now though - possibly I didn't add the other 2 keywords because no-one could agree.. or maybe it was something else that was missing :S I hope not. |
Oops, I missed @seven-phases-max's suggestions when responding, so I was only responding to @bassjobsen. @seven-phases-max I don't think they would necessarily go in pairs like that, as the other two modes are not exactly opposites. I mean, they switch on opposite switches, but the result isn't exactly a mirror of the other, so to pair them might be confusing in a different way. The logic of the keywords and their naming had to do with the switches. If you think about
So I think that because there's been only one keyword, Less authors have probably associated "all" to mean "all matches". But that's really |
Another way to say that is that these two lines are equivalent (although multiple keywords are not currently supported): .a:extend(.b deep any) {} // or .a:extend(.b !DEEP !ANY)
.a:extend(.b all) {} // or .a:extend(.b !all) Just to clarify this piece:
Is that still confusing? It matches the middle of the selector. That's why in the PR, |
I guess this is where the miscomprehension sits. Since a tree and a selector are not the same things you can't interchange them freely. E.g. the
tree creates three independent selectors having their own sets of rules, so you can (probably) say it matches in the middle of the Speaking of Speaking of the docs, curiously I just realized that the following dumb and mechanical descriptions of all three are sufficient and exhaustive: |
I agree. I was more trying to reference how extend was implemented. As I said, how the particular descriptions of keywords were written is not exactly how it was implemented. In the implementation process, it was decided that So, how it should be described or how keywords should be labeled now is a legitimate question / point. The final implementation (of
I had to re-read these descriptions a few times before I got what you were saying. While they seem cleverly technically accurate (aside from xyz not necessarily being an element), they still kind of read as "huh?" to me. The disparity in understanding is not new in regards to this feature. Extend, unlike any other feature, exposed the different "mind models" that Less authors use to approach their style sheets. Everyone was writing the same thing, but held a different model of what that "thing" was, and so when extend was introduced, we suddenly realized that we had different ideas and different internal models about the thing. So, I know how extend works, but despite the descriptions and people using it, I don't know WHY it works that way. That is, I can't grok the reasoning because I don't think along the same path. However, I know that a lot of people understand why it works that way and agree with it, and that's fine. That's a bit off-topic, except to say that I understand why we're each confused by the other person's description. So this is the labeling and description challenge. It's possible each of us won't understand the other person's reasoning, so I think the best middle ground is to find keywords / wording that sufficiently express our understanding. That is: let's keep tossing ideas back and forth until something sticks. |
More sketching: |
I get downward and the other words you've used, but I don't get the upward part, which is similar to your other key pairs. How does it extend upward? (Or "outer" or "asc".) I don't recognize that behavior in this feature. Do you have a code example that could demonstrate how it is extending "upward"? |
I'm just sketching. OK, maybe
since in:
|
Hmm, but it isn't exactly outer because of this: LESS: .a button .q {
color: red;
}
.b:extend(button any) {
background: black;
} CSS: .a button .q,
.a .b .q {
color: red;
}
.b {
background: black;
} I don't see how that matching is described as "outer". If anything it's "middle". Or end or beginning. So... any. Default extend is "exact" matching, and |
Another example of #mike.bob.joe.bill {
color: red;
}
.b:extend(#mike all) {
background: black;
}
.c:extend(.bill all) {
background: blue;
} #mike.bob.joe.bill,
.b.bob.joe.bill,
#mike.bob.joe.c {
color: red;
}
.b {
background: black;
}
.c {
background: blue;
} |
Demonstration of deep: LESS: .element {
border-color: green;
&:hover { color: blue; }
&:active { color: red; }
}
.foo:extend(.element) {}
.bar:extend(.element deep) {} CSS: .element,
.foo,
.bar {
border-color: green;
}
.element:hover,
.bar:hover {
color: blue;
}
.element:active,
.bar:active {
color: red;
} |
For your first example, no, the result of this PR is different:
So it looks like we are getting back to the top of the thread? :) P.S. So let's try again... can you, please, provide an example that shows the difference between |
Er, then that seems wrong. Since "all" is the "sum" of How do you test the PR? Is there a way to do this with npm? |
Not only would that be wrong, but it wouldn't pass the example given right at the top description of
Err, @bassjobsen ? |
I'm was under expression you can install via npm directly from github. Though to be honest I'm not sure now (personally I just checkout the branch via git). |
Yes you can. Easiest is to go the commit hash, then the tarball url for
that hash then just use the url to the tarball instead of "less" with npm.
E.g. npm install -g http://www.github.com ...
|
@lukeapage Oh, right. I saw something similar when you edit an npm module, and you can set the version to the tarball URL from Github in your package dependencies. Thanks! That makes life easier. |
Please re-open when/if this is ready |
@bassjobsen Pinging again to see if you want to address the remaining issues. |
@matthew-dean i will try soon |
No description provided.