Added support for "extends" in layouts
parent
75c01f7d9e
commit
373d841823
|
|
@ -6,7 +6,8 @@ Squib is a Ruby [DSL](http://en.wikipedia.org/wiki/Domain-specific_language) for
|
|||
* Reading `.xlsx` files
|
||||
* Basic shape drawing
|
||||
* Rendering to PNGs and PDFs
|
||||
* Unit conversion (inches)
|
||||
* Unit conversion
|
||||
* Specfiying your layouts in a YML file
|
||||
* Plus the full power of Ruby!
|
||||
|
||||
Check this out.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
require 'yaml'
|
||||
require 'pp'
|
||||
require 'squib/card'
|
||||
require 'squib/input_helpers'
|
||||
require 'squib/constants'
|
||||
|
|
@ -86,7 +87,16 @@ module Squib
|
|||
# @api private
|
||||
def load_layout(file)
|
||||
return if file.nil?
|
||||
@layout = YAML.load_file(file)
|
||||
prelayout = YAML.load_file(file)
|
||||
@layout = {}
|
||||
prelayout.each do |key, value|
|
||||
if value.key? "extends"
|
||||
@layout[key] = prelayout[value["extends"]].merge prelayout[key]
|
||||
else
|
||||
@layout[key] = value
|
||||
end
|
||||
end
|
||||
Squib::logger.warn "Multi-level extends not supported. If you want them, contact the developer." if @layout.to_s.include? '"extends"=>'
|
||||
end
|
||||
|
||||
##################
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ module Squib
|
|||
end
|
||||
module_function :needs
|
||||
|
||||
# @api private
|
||||
def layoutify(opts)
|
||||
unless opts[:layout].nil?
|
||||
entry = @layout[opts[:layout].to_s]
|
||||
|
|
|
|||
|
|
@ -3,25 +3,32 @@ frame:
|
|||
y: 38
|
||||
width: 750
|
||||
height: 1050
|
||||
radius: 25
|
||||
title:
|
||||
x: 125
|
||||
y: 50
|
||||
width: 625
|
||||
height: 150
|
||||
align: !ruby/symbol center
|
||||
hint: !ruby/symbol cyan
|
||||
height: 100
|
||||
align: !ruby/symbol center #see http://www.yaml.org/YAML_for_ruby.html#symbols
|
||||
valign: !ruby/symbol middle
|
||||
subtitle:
|
||||
x: 125
|
||||
x: 150
|
||||
y: 150
|
||||
width: 625
|
||||
height: 150
|
||||
icon_left:
|
||||
x: 200
|
||||
y: 250
|
||||
width: 575
|
||||
height: 60
|
||||
align: !ruby/symbol center
|
||||
valign: !ruby/symbol middle
|
||||
icon:
|
||||
width: 125
|
||||
height: 125
|
||||
icon_right:
|
||||
x: 400
|
||||
y: 250
|
||||
width: 125
|
||||
height: 125
|
||||
icon_left:
|
||||
extends: icon
|
||||
x: 150
|
||||
icon_middle:
|
||||
extends: icon
|
||||
x: 350
|
||||
y: 400 #overrides the y inherited from icon
|
||||
icon_right:
|
||||
extends: icon
|
||||
x: 550
|
||||
|
|
|
|||
|
|
@ -2,20 +2,28 @@ require 'squib'
|
|||
|
||||
Squib::Deck.new(layout: 'custom-layout.yml') do
|
||||
background color: :white
|
||||
hint text: :cyan
|
||||
|
||||
# Layouts are YAML files that specify x, y, width, and height coordinates
|
||||
# Layouts are YAML files that specify any option as a default
|
||||
rect layout: :frame
|
||||
|
||||
# You can also override a given layout entry in the command
|
||||
rect layout: :frame, width: 50, height: 50
|
||||
circle layout: :frame, x: 50, y: 50, radius: 25
|
||||
|
||||
# Any command with x-y-width-height options, we can use a custom layout
|
||||
text str: 'The Title', layout: :title
|
||||
png file: 'shiny-purse.png', layout: :icon_left
|
||||
|
||||
# Layouts also support an "extends" attribute to reuse settings
|
||||
svg file: 'spanner.svg', layout: :icon_left
|
||||
png file: 'shiny-purse.png', layout: :icon_middle
|
||||
svg file: 'spanner.svg', layout: :icon_right
|
||||
|
||||
# Strings can also be used in layouts
|
||||
# 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
|
||||
Loading…
Reference in New Issue