Added support for merging multiple layout files
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
title:
|
||||
x: 100
|
||||
subtitle:
|
||||
x: 200
|
||||
@@ -0,0 +1,4 @@
|
||||
title: # redefined
|
||||
x: 300
|
||||
desc:
|
||||
x: 400
|
||||
@@ -0,0 +1,8 @@
|
||||
grandparent:
|
||||
x: 100
|
||||
parent_a:
|
||||
extends: grandparent
|
||||
x: += 10 # evaluates to 110
|
||||
parent_b:
|
||||
extends: grandparent
|
||||
x: += 20 # evaluates to 120, for now...
|
||||
@@ -0,0 +1,9 @@
|
||||
child_a:
|
||||
extends: parent_a
|
||||
x: += 3 # evaluates to 113
|
||||
parent_b: # redefined
|
||||
extends: grandparent
|
||||
x: += 30 # evaluates to 130
|
||||
child_b:
|
||||
extends: parent_b
|
||||
x: += 3 # evaluates to 133
|
||||
@@ -183,6 +183,30 @@ describe Squib::Deck do
|
||||
raise_error(RuntimeError, 'Invalid layout: circular extends with \'a\'')
|
||||
end
|
||||
|
||||
it 'redefines keys on multiple layouts' do
|
||||
a = test_file('multifile-a.yml')
|
||||
b = test_file('multifile-b.yml')
|
||||
d = Squib::Deck.new(layout: [a, b])
|
||||
expect(d.layout).to eq({
|
||||
'title' => { 'x' => 300 },
|
||||
'subtitle' => { 'x' => 200 },
|
||||
'desc' => { 'x' => 400 }
|
||||
})
|
||||
end
|
||||
|
||||
it 'evaluates extends on each file first' do
|
||||
a = test_file('multifile-extends-a.yml')
|
||||
b = test_file('multifile-extends-b.yml')
|
||||
d = Squib::Deck.new(layout: [a, b])
|
||||
expect(d.layout).to eq({
|
||||
'grandparent' => { 'x' => 100 },
|
||||
'parent_a' => { 'x' => 110, 'extends' => 'grandparent' },
|
||||
'parent_b' => { 'x' => 130, 'extends' => 'grandparent' },
|
||||
'child_a' => { 'x' => 113, 'extends' => 'parent_a' },
|
||||
'child_b' => { 'x' => 133, 'extends' => 'parent_b' }
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user