parent
b74fbf5787
commit
955d64a01f
|
|
@ -0,0 +1,16 @@
|
|||
use_layout
|
||||
==========
|
||||
|
||||
Load a layout file and merge into the current set of layouts.
|
||||
|
||||
Options
|
||||
-------
|
||||
|
||||
file
|
||||
default: ``'layout.yml'``
|
||||
|
||||
The file or array of files to load. Treated exactly how :doc:`/dsl/deck` parses it.
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
|
@ -31,5 +31,11 @@ module Squib
|
|||
@font = (opts[:font] == :default) ? Squib::DEFAULT_FONT: opts[:font]
|
||||
end
|
||||
|
||||
# Load a new layout into the deck
|
||||
# @api public
|
||||
def use_layout(file: 'layout.yml')
|
||||
@layout = LayoutParser.load_layout(file, @layout)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ module Squib
|
|||
|
||||
# Load the layout file(s), if exists
|
||||
# @api private
|
||||
def self.load_layout(files)
|
||||
layout = {}
|
||||
def self.load_layout(files, initial = {})
|
||||
layout = initial
|
||||
Squib::logger.info { " using layout(s): #{files}" }
|
||||
Array(files).each do |file|
|
||||
thefile = file
|
||||
|
|
|
|||
|
|
@ -60,3 +60,13 @@ Squib::Deck.new(layout: 'hand.yml') do
|
|||
png file: 'pokercard.png', alpha: 0.5
|
||||
save_png prefix: 'layout_builtin_hand_'
|
||||
end
|
||||
|
||||
# Layouts can also be specified in their own DSL method call
|
||||
# Each layout call will progressively be merged with the priors
|
||||
Squib::Deck.new do
|
||||
use_layout file: 'custom-layout.yml'
|
||||
use_layout file: 'custom-layout2.yml'
|
||||
text str: 'The Title', layout: :title # from custom-layout.yml
|
||||
text str: 'The Subtitle',layout: :subtitle # redefined in custom-layout2.yml
|
||||
save_png prefix: 'layout3_'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -186,4 +186,16 @@ describe Squib::LayoutParser do
|
|||
})
|
||||
end
|
||||
|
||||
end
|
||||
it 'loads progressively on multiple calls' do
|
||||
a = layout_file('multifile-a.yml')
|
||||
b = layout_file('multifile-b.yml')
|
||||
layout = Squib::LayoutParser.load_layout(a)
|
||||
layout = Squib::LayoutParser.load_layout(b, layout)
|
||||
expect(layout).to eq({
|
||||
'title' => { 'x' => 300 },
|
||||
'subtitle' => { 'x' => 200 },
|
||||
'desc' => { 'x' => 400 }
|
||||
})
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue