Added support for merging multiple layout files

This commit is contained in:
Andy Meneely
2014-11-17 21:08:57 -05:00
parent dbc1b6eab3
commit 75ab0b565f
11 changed files with 122 additions and 8 deletions
+4
View File
@@ -0,0 +1,4 @@
title:
x: 100
subtitle:
x: 200
+4
View File
@@ -0,0 +1,4 @@
title: # redefined
x: 300
desc:
x: 400
+8
View File
@@ -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...
+9
View File
@@ -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
+24
View File
@@ -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