Bringing back the extends feature

Adding in my own merge key implementation that allows you to bring in
other keys and modfiy the data. Makes moving boxes around easier.

A quasi-revert of 00e8b59144
...but with something useful!
This commit is contained in:
Andy Meneely
2014-09-21 21:56:18 -04:00
parent b5ff2890d0
commit f2a2ab0573
13 changed files with 186 additions and 29 deletions
+6
View File
@@ -0,0 +1,6 @@
a:
extends: b
x: 50
b:
extends: a
x: 150
+9
View File
@@ -0,0 +1,9 @@
a:
extends: c
x: 50
b:
extends: a
x: 150
c:
extends: b
y: 250
+5 -4
View File
@@ -1,13 +1,14 @@
aunt: &aunt
aunt:
a: 101
b: 102
c: 103
uncle: &uncle
uncle:
x: 104
y: 105
b: 106
child:
<<: *uncle
<<: *aunt
extends:
- uncle
- aunt
a: 107
x: 108
+5 -5
View File
@@ -1,10 +1,10 @@
frame: &frame
frame:
x: 38
y: 38
title: &title
<<: *frame
title:
extends: frame
y: 50
width: 100
subtitle:
<<: *title
subtitle:
extends: title
y: 150
+7
View File
@@ -0,0 +1,7 @@
title:
extends: frame
y: 50
width: 100
frame:
x: 38
y: 38
+3
View File
@@ -0,0 +1,3 @@
a:
extends: a
x: 50
+2 -2
View File
@@ -1,7 +1,7 @@
frame: &frame
frame:
x: 38
y: 38
title:
<<: *frame
extends: frame
y: 50
width: 100
+3 -3
View File
@@ -1,12 +1,12 @@
frame: &frame
frame:
x: 38
y: 38
title:
<<: *frame
extends: frame
y: 50
width: 100
title2:
<<: *frame
extends: frame
x: 75
y: 150
width: 150
+41
View File
@@ -68,6 +68,24 @@ describe Squib::Deck do
'y' => 38,
},
'title' => {
'extends' => 'frame',
'x' => 38,
'y' => 50,
'width' => 100,
}
}
)
end
it "applies the extends regardless of order" do
d = Squib::Deck.new(layout: test_file('pre-extends.yml'))
expect(d.layout).to \
eq({'frame' => {
'x' => 38,
'y' => 38,
},
'title' => {
'extends' => 'frame',
'x' => 38,
'y' => 50,
'width' => 100,
@@ -84,11 +102,13 @@ describe Squib::Deck do
'y' => 38,
},
'title' => {
'extends' => 'frame',
'x' => 38,
'y' => 50,
'width' => 100,
},
'title2' => {
'extends' => 'frame',
'x' => 75,
'y' => 150,
'width' => 150,
@@ -111,6 +131,7 @@ describe Squib::Deck do
'b' => 106,
},
'child' => {
'extends' => ['uncle','aunt'],
'a' => 107, # my own
'b' => 102, # from the younger aunt
'c' => 103, # from aunt
@@ -129,11 +150,13 @@ describe Squib::Deck do
'y' => 38,
},
'title' => {
'extends' => 'frame',
'x' => 38,
'y' => 50,
'width' => 100,
},
'subtitle' => {
'extends' => 'title',
'x' => 38,
'y' => 150,
'width' => 100,
@@ -142,6 +165,24 @@ describe Squib::Deck do
)
end
it "fails on a self-circular extends" do
file = test_file('self-circular-extends.yml')
expect { Squib::Deck.new(layout: file) }.to \
raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
end
it "fails on a easy-circular extends" do
file = test_file('easy-circular-extends.yml')
expect { Squib::Deck.new(layout: file) }.to \
raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
end
it "hard on a easy-circular extends" do
file = test_file('hard-circular-extends.yml')
expect { Squib::Deck.new(layout: file) }.to \
raise_error(RuntimeError, "Invalid layout: circular extends with 'a'")
end
end
end