change x= to *=, add unit tests and improve existing tests
parent
b3bd8f03d8
commit
8509ab5728
|
|
@ -117,7 +117,7 @@ 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 multiply the inherited number by the given number
|
||||
* ``/=`` will divide the inherited number by the given number
|
||||
|
||||
``+=`` and ``-=`` also support :doc:`/units`
|
||||
|
|
@ -154,7 +154,7 @@ As you might expect, ``extends`` can be composed multiple times::
|
|||
x: += 10 # evaluates to 110
|
||||
aristotle:
|
||||
extends: plato
|
||||
x: x= 2 # evaluates to 220
|
||||
x: "*= 2" # evaluates to 220, note that YAML requires quotes here
|
||||
|
||||
Yes, ``extends`` has Multiple Inheritance
|
||||
-----------------------------------------
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ 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=')
|
||||
elsif child_val.to_s.strip.start_with?('*=')
|
||||
mul_parent_child(parent_val, child_val)
|
||||
elsif child_val.to_s.strip.start_with?('/=')
|
||||
div_parent_child(parent_val, child_val)
|
||||
|
|
@ -82,7 +82,7 @@ module Squib
|
|||
|
||||
def mul_parent_child(parent, child)
|
||||
parent_pixels = Args::UnitConversion.parse(parent, @dpi).to_f
|
||||
child_float = child.sub('x=', '').to_f
|
||||
child_float = child.sub('*=', '').to_f
|
||||
parent_pixels * child_float
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
parent:
|
||||
x: 0.5in
|
||||
x: 100
|
||||
y: 1in
|
||||
width: 200
|
||||
height: 1cm
|
||||
|
||||
child:
|
||||
extends: parent
|
||||
x: += 1in
|
||||
y: -= 0.5in
|
||||
y: -= 1cm
|
||||
width: "*= 1.5"
|
||||
height: /= 4
|
||||
|
|
|
|||
|
|
@ -206,8 +206,13 @@ describe Squib::LayoutParser do
|
|||
it 'does mixed unit conversion when extending' do
|
||||
layout = subject.load_layout(layout_file('extends-units-mixed.yml'))
|
||||
expect(layout).to eq({
|
||||
'parent' => { 'x' => '0.5in', 'y' => '1in'},
|
||||
'child' => { 'x' => 450.0, 'y' => 150.0, 'extends' => 'parent' },
|
||||
'parent' => {
|
||||
'x' => 100, 'y' => '1in',
|
||||
'width' => 200, 'height' => '1cm' },
|
||||
'child' => {
|
||||
'x' => 400.0, 'y' => 181.8897639,
|
||||
'width' => 300.0, 'height' => 29.527559025,
|
||||
'extends' => 'parent' },
|
||||
})
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue