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
+29 -9
View File
@@ -18,22 +18,42 @@ subtitle:
height: 60
align: !ruby/symbol center
valign: !ruby/symbol middle
# Yaml has this beautfiul feature for us: merge keys
# http://www.yaml.org/YAML_for_ruby.html#merge_key
# Define an alias with &foo, then use <<: *foo to include it
# Everything gets merged, with later merges overriding
icon: &icon
icon:
width: 125
height: 125
y: 250
icon_left:
<<: *icon
extends: icon
x: 150
icon_middle:
<<: *icon
extends: icon
x: 350
y: 400 #overrides the y inherited from icon
icon_right:
<<: *icon
extends: icon
x: 550
# Squib also supports its own merging-and-modify feature
# Called "extends"
# Any layout can extend another layout, so long as it's not a circle
# Order doesn't matter since it's done after YAML procesing
# And, if the entry overrides
bonus: #becomes our bonus rectangle
x: 250
y: 600
width: 300
height: 200
radius: 32
bonus_inner:
extends: bonus
x: += 10 # i.e. 260
y: += 10 # i.e. 610
width: -= 20 # i.e. 180
height: -= 20 # i.e. 180
radius: -= 8
bonus_text:
extends: bonus_inner
x: +=10
y: +=10
width: -= 20
height: -= 20
+7 -2
View File
@@ -13,17 +13,22 @@ Squib::Deck.new(layout: 'custom-layout.yml') do
# Lots of commands have the :layout option
text str: 'The Title', layout: :title
# Layouts also support an "extends" attribute to reuse settings
# Layouts also support YAML merge keys toreuse settings
svg file: 'spanner.svg', layout: :icon_left
png file: 'shiny-purse.png', layout: :icon_middle
svg file: 'spanner.svg', layout: :icon_right
# Squib has its own, richer merge key: "extends"
rect fill_color: :black, layout: :bonus
rect fill_color: :white, layout: :bonus_inner
text str: 'Extends!', layout: :bonus_text
# Strings can also be used to specify a layout (e.g. from a data file)
text str: 'subtitle', layout: 'subtitle'
# For debugging purposes, you can always print out the loaded layout
#require 'pp'
#pp @layout
save_png prefix: 'layout_'
end