gss / parser

Constraint Cascading Style Sheets compiler
MIT License
48 stars 6 forks source link

Support for defining virtual constraints in rule blocks #22

Closed paulyoung closed 9 years ago

paulyoung commented 10 years ago

I'd find it useful to be able to do this:

"foo" {
  left: == ::[left];
  width: == ::[width];
}

as opposed to this:

"foo"[left] == ::[left];
"foo"[width] == ::[width];
Inviz commented 10 years ago

The problem here is the meaning of :: inside the rule. In the wip version of GSS, :: points to the object matched by the current rule. Which is a virtual in this case. If we suppose that virtual constraints would be simply a rule, then we'll need to use some other pseudo selector to refer to element matched by parent rule.

I imagine that we'll have these pseudo classes:

Why ::that is a good idea? Because it works as mixins - you can bind your properties to the scope of a parent rule (or global scope).

So yes,

"foo" {
  left: ::that[left]; /*Note that == is not necessary now*/
  width: ::that[width];
}

or

"foo" {
  ::[left] == ::that[left];
  ::[width] == ::that[width];
}

is going to work. Optionally, we could add some sugar:

"foo" {
  &[left] == ^[left];   // & points to ::this, ^ to ::that 
  width: ^[width];
}
paulyoung commented 10 years ago

I think I complicated things a little by using ::.

I suppose it would be fine to say that left: == ::[left]; makes no sense inside of a virtual. I would expect width: == ::[height]; to be valid though...

I like the idea of using ^ to mean the parent element.

Inviz commented 10 years ago

:: makes sense if you do this inside virtual:

"something" { 
  left: 20%
  right: &[left]
}

because virtual is basically a container for variables, so it should be able to refer its own properties

paulyoung commented 9 years ago

I believe my original request is now possible via the parent scope selector:

"foo" {
  left: == ^[left];
  width: == ^[width];
}