Better handling of empty files
parent
a71fd8f81a
commit
5c6149ad5a
|
|
@ -9,7 +9,7 @@ module Squib
|
|||
# png file: 'img.png', x: 50, y: 50
|
||||
#
|
||||
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
||||
# @option opts file [String, Array] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. See {file:API.md#Specifying+Files Specifying Files}
|
||||
# @option opts file [String, Array] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:API.md#Specifying+Files Specifying Files}
|
||||
# @option opts x [Integer] (0) the x-coordinate to place
|
||||
# @option opts y [Integer] (0) the y-coordinate to place
|
||||
# @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:API.md#label-Custom+Layouts Custom Layouts}
|
||||
|
|
@ -30,7 +30,7 @@ module Squib
|
|||
# svg 1..2, 'icon.svg', '#stone', x: 50, y:50
|
||||
#
|
||||
# @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
|
||||
# @option opts file [String, Array] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. See {file:API.md#Specifying+Files Specifying Files}
|
||||
# @option opts file [String, Array] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:API.md#Specifying+Files Specifying Files}
|
||||
# @option opts x [Integer] (0) the x-coordinate to place
|
||||
# @option opts y [Integer] (0) the y-coordinate to place
|
||||
# @option opts width [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ module Squib
|
|||
# :nodoc:
|
||||
# @api private
|
||||
def png(file, x, y, alpha)
|
||||
return if file.nil? or file.eql? ''
|
||||
cc = cairo_context
|
||||
png = Cairo::ImageSurface.from_png(file)
|
||||
cc.set_source(png, x, y)
|
||||
|
|
@ -13,6 +14,7 @@ module Squib
|
|||
# :nodoc:
|
||||
# @api private
|
||||
def svg(file, id, x, y, width, height)
|
||||
return if file.nil? or file.eql? ''
|
||||
svg = RSVG::Handle.new_from_file(file)
|
||||
width = svg.width if width == :native
|
||||
height = svg.height if height == :native
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ module Squib
|
|||
opts = Squib::SYSTEM_DEFAULTS.merge(opts)
|
||||
opts = rangeify(opts) if params.include? :range
|
||||
opts = fileify(opts) if params.include? :file
|
||||
opts = fileify(opts, false, true) if params.include? :file_to_save
|
||||
opts = fileify(opts, true) if params.include? :files
|
||||
opts = fileify(opts, false, false) if params.include? :file_to_save
|
||||
opts = fileify(opts, true, false) if params.include? :files
|
||||
opts = colorify(opts) if params.include? :color
|
||||
opts = colorify(opts, true) if params.include? :nillable_color
|
||||
opts = dirify(opts) if params.include? :dir
|
||||
|
|
@ -68,11 +68,11 @@ module Squib
|
|||
|
||||
# :nodoc:
|
||||
# @api private
|
||||
def fileify(opts, expand_singletons=false, allow_non_exist=false)
|
||||
opts[:file] = [opts[:file]] * @cards.size if expand_singletons
|
||||
def fileify(opts, expand_singletons=false, file_must_exist=true)
|
||||
opts[:file] = [opts[:file]] * @cards.size if expand_singletons && !(opts[:file].respond_to? :each)
|
||||
files = [opts[:file]].flatten
|
||||
files.each do |file|
|
||||
unless File.exists?(file) || allow_non_exist
|
||||
if file_must_exist and !File.exists?(file)
|
||||
raise "File #{File.expand_path(file)} does not exist!"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue