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``
|
||||
* ``+=`` will add the giuven number to 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::
|
||||
|
||||
|
|
@ -149,10 +151,10 @@ As you might expect, ``extends`` can be composed multiple times::
|
|||
x: 100
|
||||
plato:
|
||||
extends: socrates
|
||||
x: += 10 # evaluates to 150
|
||||
x: += 10 # evaluates to 110
|
||||
aristotle:
|
||||
extends: plato
|
||||
x: += 20 # evaluates to 150
|
||||
x: x= 2 # evaluates to 220
|
||||
|
||||
Yes, ``extends`` has Multiple Inheritance
|
||||
-----------------------------------------
|
||||
|
|
@ -167,7 +169,7 @@ If you want to extend multiple parents, it looks like this::
|
|||
extends:
|
||||
- socrates
|
||||
- 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::
|
||||
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ module Squib
|
|||
add_parent_child(parent_val, child_val)
|
||||
elsif child_val.to_s.strip.start_with?('-=')
|
||||
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
|
||||
child_val # child overrides parent when merging, no +=
|
||||
end
|
||||
|
|
@ -76,6 +80,18 @@ module Squib
|
|||
parent_pixels - child_pixels
|
||||
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?
|
||||
# i.e. is it a base-case or will it need recursion?
|
||||
# :nodoc:
|
||||
|
|
|
|||
Loading…
Reference in New Issue