Better ability to handle per-dsl-method defaults
This commit is contained in:
@@ -48,12 +48,11 @@ module Squib
|
||||
# @return [Array] Returns an Array of hashes keyed by :width and :height that mark the ink extents of the text rendered.
|
||||
# @api public
|
||||
def text(opts = {})
|
||||
opts = { stroke_width: 0, width: :auto, height: :auto }.merge(opts)
|
||||
range = Args::CardRange.new(opts[:range], deck_size: size)
|
||||
para = Args::Paragraph.new(font).load!(opts, expand_by: size, layout: layout)
|
||||
box = Args::Box.new(self).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
box = Args::Box.new(self, {width: :auto, height: :auto}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
trans = Args::Transform.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
draw = Args::Draw.new(custom_colors).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
draw = Args::Draw.new(custom_colors, {stroke_width: 0.0}).load!(opts, expand_by: size, layout: layout, dpi: dpi)
|
||||
embed = TextEmbed.new
|
||||
yield(embed) if block_given? #store the opts for later use
|
||||
extents = Array.new(@cards.size)
|
||||
|
||||
@@ -45,18 +45,21 @@ module Squib
|
||||
# (1) Use whatever is specified if it is
|
||||
# (2) Go over all layout specifications (if any) and look them up
|
||||
# - Use layout when it's specified for that card
|
||||
# - Use default if no layout was specified,
|
||||
# or the layout itself did not specify
|
||||
# - Use "default" if no layout was specified, or the layout itself did not specify
|
||||
# Defaut can be overriden for a given dsl method (@dsl_method_defaults)
|
||||
# (e.g stroke width is 0.0 for text, non-zero everywhere else)
|
||||
#
|
||||
def defaultify(p, args, layout)
|
||||
return args[p] if args.key? p # arg was specified, no defaults used
|
||||
dsl_method_defaults = @dsl_method_defaults || {}
|
||||
args[:layout].map do |layout_arg|
|
||||
if layout_arg.nil?
|
||||
self.class.parameters[p] # no layout specified, use default
|
||||
self.class.parameters.merge(dsl_method_defaults)[p] # no layout specified, use default
|
||||
else
|
||||
if layout[layout_arg.to_s].key? p.to_s
|
||||
layout[layout_arg.to_s][p.to_s] # param specified in layout
|
||||
else
|
||||
self.class.parameters[p] # layout specified, but not this param
|
||||
self.class.parameters.merge(dsl_method_defaults)[p] # layout specified, but not this param
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,8 +7,9 @@ module Squib
|
||||
class Box
|
||||
include ArgLoader
|
||||
|
||||
def initialize(deck = nil)
|
||||
def initialize(deck = nil, dsl_method_defaults = {})
|
||||
@deck = deck
|
||||
@dsl_method_defaults = dsl_method_defaults
|
||||
end
|
||||
|
||||
def self.parameters
|
||||
|
||||
@@ -10,9 +10,10 @@ module Squib
|
||||
include ArgLoader
|
||||
include ColorValidator
|
||||
|
||||
def initialize(custom_colors)
|
||||
def initialize(custom_colors, dsl_method_defaults = {})
|
||||
@custom_colors = custom_colors
|
||||
end
|
||||
@dsl_method_defaults = dsl_method_defaults
|
||||
end
|
||||
|
||||
def self.parameters
|
||||
{ color: :black,
|
||||
|
||||
Reference in New Issue
Block a user