Implementing an img_dir configuration setting
This commit is contained in:
+14
-10
@@ -19,10 +19,12 @@ module Squib
|
||||
# @api public
|
||||
def png(opts = {})
|
||||
opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend])
|
||||
@progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar|
|
||||
opts[:range].each do |i|
|
||||
@cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
|
||||
bar.increment
|
||||
Dir.chdir(@img_dir) do
|
||||
@progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar|
|
||||
opts[:range].each do |i|
|
||||
@cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
|
||||
bar.increment
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -48,13 +50,15 @@ module Squib
|
||||
# @api public
|
||||
def svg(opts = {})
|
||||
p = needs(opts,[:range, :files, :svgid, :force_svgid, :x, :y, :width, :height, :layout, :alpha, :blend])
|
||||
@progress_bar.start("Loading SVG(s)", p[:range].size) do |bar|
|
||||
p[:range].each do |i|
|
||||
unless p[:force_id][i] && p[:id][i].to_s.empty?
|
||||
@cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
|
||||
p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i])
|
||||
Dir.chdir(@img_dir) do
|
||||
@progress_bar.start("Loading SVG(s)", p[:range].size) do |bar|
|
||||
p[:range].each do |i|
|
||||
unless p[:force_id][i] && p[:id][i].to_s.empty?
|
||||
@cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
|
||||
p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i])
|
||||
end
|
||||
bar.increment
|
||||
end
|
||||
bar.increment
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ module Squib
|
||||
@text_hint = text
|
||||
end
|
||||
|
||||
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves
|
||||
# Sets various defaults for this deck. Defaults can be overriden by the commands themselves when that command supports it.
|
||||
# @example
|
||||
# set font: 'Arial 26'
|
||||
# text 'blah' # in Arial 26
|
||||
@@ -25,11 +25,13 @@ module Squib
|
||||
# set font: :default # Back to Squib-wide default
|
||||
#
|
||||
# @option opts font: the font string to set as default. Can also be set to `:default` to use the Squib-wide default.
|
||||
# @option opts img_dir: the default directory to READ images from. Default is `.`. Useful for switching from bw to color images.
|
||||
# @return [nil] Returns nothing
|
||||
# @api public
|
||||
def set(opts = {})
|
||||
opts = needs(opts, [:font])
|
||||
opts = needs(opts, [:font, :img_dir])
|
||||
@font = opts[:font][0] #was expanded - just need the first
|
||||
@img_dir = opts[:img_dir]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -17,6 +17,7 @@ module Squib
|
||||
:gap => 0,
|
||||
:height => :native,
|
||||
:hint => :off,
|
||||
:img_dir => '.',
|
||||
:justify => false,
|
||||
:margin => 75,
|
||||
:markup => false,
|
||||
@@ -53,6 +54,7 @@ module Squib
|
||||
'dpi' => 300,
|
||||
'hint' => :none,
|
||||
'progress_bar' => false,
|
||||
'img_dir' => '.',
|
||||
}
|
||||
|
||||
# These are parameters that are intended to be "expanded" across
|
||||
|
||||
@@ -96,6 +96,7 @@ module Squib
|
||||
@text_hint = config['text_hint']
|
||||
@progress_bar.enabled = config['progress_bars']
|
||||
@custom_colors = config['custom_colors']
|
||||
@img_dir = config['img_dir']
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -16,7 +16,8 @@ module Squib
|
||||
opts = fileify(opts) if params.include? :file
|
||||
opts = fileify(opts, false) if params.include? :file_to_save
|
||||
opts = colorify(opts, true) if params.include? :nillable_color
|
||||
opts = dirify(opts, true) if params.include? :creatable_dir
|
||||
opts = dirify(opts, :dir, true) if params.include? :creatable_dir
|
||||
opts = dirify(opts, :img_dir, false) if params.include? :img_dir
|
||||
opts = fileify(opts, false) if params.include? :files
|
||||
opts = colorify(opts) if params.include? :color
|
||||
opts = colorify(opts, false, :fill_color) if params.include? :fill_color
|
||||
@@ -107,14 +108,14 @@ module Squib
|
||||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def dirify(opts, allow_create=false)
|
||||
return opts if Dir.exists?(opts[:dir])
|
||||
def dirify(opts, key, allow_create=false)
|
||||
return opts if Dir.exists?(opts[key])
|
||||
if allow_create
|
||||
Squib.logger.warn {"Dir #{opts[:dir]} does not exist, creating it."}
|
||||
Dir.mkdir opts[:dir]
|
||||
Squib.logger.warn {"Dir #{opts[key]} does not exist, creating it."}
|
||||
Dir.mkdir opts[key]
|
||||
return opts
|
||||
else
|
||||
raise "'#{opts[:dir]}' does not exist!"
|
||||
raise "'#{opts[key]}' does not exist!"
|
||||
end
|
||||
end
|
||||
module_function :dirify
|
||||
|
||||
@@ -13,4 +13,8 @@
|
||||
|
||||
#Enable some custom colors that can be used in any color
|
||||
#custom_colors:
|
||||
# foo: '#abc'
|
||||
# foo: '#abc'
|
||||
|
||||
#For reading image file command (e.g. png and svg), read from this directory instead
|
||||
#img_dir: img-color
|
||||
#img_dir: img-bw
|
||||
Reference in New Issue
Block a user