add x= and /= to extends values
parent
2a86b8f215
commit
b3bd8f03d8
|
|
@ -117,8 +117,10 @@ You can also **modify** data as they get passed through extends::
|
||||||
The following operators are supported within evaluating ``extends``
|
The following operators are supported within evaluating ``extends``
|
||||||
* ``+=`` will add the giuven number to the inherited number
|
* ``+=`` will add the giuven number to the inherited number
|
||||||
* ``-=`` will subtract the given number from the inherited number
|
* ``-=`` will subtract the given number from the inherited number
|
||||||
|
* ``x=`` will multiply the inherited number by the given number
|
||||||
|
* ``/=`` will divide the inherited number by the given number
|
||||||
|
|
||||||
Both operators also support :doc:`/units`
|
``+=`` and ``-=`` also support :doc:`/units`
|
||||||
|
|
||||||
From a design point of view, you can also extract out a base design and have your other layouts extend from them::
|
From a design point of view, you can also extract out a base design and have your other layouts extend from them::
|
||||||
|
|
||||||
|
|
@ -149,10 +151,10 @@ As you might expect, ``extends`` can be composed multiple times::
|
||||||
x: 100
|
x: 100
|
||||||
plato:
|
plato:
|
||||||
extends: socrates
|
extends: socrates
|
||||||
x: += 10 # evaluates to 150
|
x: += 10 # evaluates to 110
|
||||||
aristotle:
|
aristotle:
|
||||||
extends: plato
|
extends: plato
|
||||||
x: += 20 # evaluates to 150
|
x: x= 2 # evaluates to 220
|
||||||
|
|
||||||
Yes, ``extends`` has Multiple Inheritance
|
Yes, ``extends`` has Multiple Inheritance
|
||||||
-----------------------------------------
|
-----------------------------------------
|
||||||
|
|
@ -167,7 +169,7 @@ If you want to extend multiple parents, it looks like this::
|
||||||
extends:
|
extends:
|
||||||
- socrates
|
- socrates
|
||||||
- plato
|
- plato
|
||||||
x: += 50 # evaluates to 150
|
x: += 50 # evaluates to 250 from plato
|
||||||
|
|
||||||
If multiple keys override the same keys in a parent, the later ("younger") child in the ``extends`` list takes precedent. Like this::
|
If multiple keys override the same keys in a parent, the later ("younger") child in the ``extends`` list takes precedent. Like this::
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ module Squib
|
||||||
add_parent_child(parent_val, child_val)
|
add_parent_child(parent_val, child_val)
|
||||||
elsif child_val.to_s.strip.start_with?('-=')
|
elsif child_val.to_s.strip.start_with?('-=')
|
||||||
sub_parent_child(parent_val, child_val)
|
sub_parent_child(parent_val, child_val)
|
||||||
|
elsif child_val.to_s.strip.start_with?('x=')
|
||||||
|
mul_parent_child(parent_val, child_val)
|
||||||
|
elsif child_val.to_s.strip.start_with?('/=')
|
||||||
|
div_parent_child(parent_val, child_val)
|
||||||
else
|
else
|
||||||
child_val # child overrides parent when merging, no +=
|
child_val # child overrides parent when merging, no +=
|
||||||
end
|
end
|
||||||
|
|
@ -76,6 +80,18 @@ module Squib
|
||||||
parent_pixels - child_pixels
|
parent_pixels - child_pixels
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mul_parent_child(parent, child)
|
||||||
|
parent_pixels = Args::UnitConversion.parse(parent, @dpi).to_f
|
||||||
|
child_float = child.sub('x=', '').to_f
|
||||||
|
parent_pixels * child_float
|
||||||
|
end
|
||||||
|
|
||||||
|
def div_parent_child(parent, child)
|
||||||
|
parent_pixels = Args::UnitConversion.parse(parent, @dpi).to_f
|
||||||
|
child_float = child.sub('/=', '').to_f
|
||||||
|
parent_pixels / child_float
|
||||||
|
end
|
||||||
|
|
||||||
# Does this layout entry have an extends field?
|
# Does this layout entry have an extends field?
|
||||||
# i.e. is it a base-case or will it need recursion?
|
# i.e. is it a base-case or will it need recursion?
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue