lib/img_props.rb in jekyll_img-0.1.2 vs lib/img_props.rb in jekyll_img-0.1.3
- old
+ new
@@ -1,12 +1,15 @@
+class ImgError < StandardError; end
+
# Properties from user
# All methods are idempotent.
# attr_ methods can be called after compute_dependant_properties
# All methods except compute_dependant_properties can be called in any order
class ImgProperties
- attr_accessor :align, :alt, :attr_wrapper_align_class, :caption, :classes, :id, :img_display, :nofollow, \
- :src, :size, :style, :target, :title, :url, :wrapper_class, :wrapper_style
+ attr_accessor :align, :alt, :attr_wrapper_align_class, :caption, :classes, :continue_on_error, \
+ :id, :img_display, :nofollow, :src, :size, :style, :target, :title, \
+ :url, :wrapper_class, :wrapper_style
SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze
def attr_alt
"alt='#{@alt}'" if @alt
@@ -26,12 +29,14 @@
end
def attr_size_class
return nil if @size == false || @size.nil? || size_unit_specified?
- abort "'#{@size}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit." \
- unless SIZES.include?(@size)
+ unless SIZES.include?(@size)
+ msg = "'#{@size}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit."
+ raise ImgError, msg
+ end
@size
end
def attr_style_img
"style='width: 100%; #{@style}'".squish
@@ -58,15 +63,15 @@
@target ||= '_blank'
@img_display = @caption && @size ? 'imgBlock' : 'imgFlex'
@alt ||= @caption || @title
- @title ||= @caption || @alt # rubocop:disable Naming/MemoizedInstanceVariableName
+ @title ||= @caption || @alt
end
def src_png
- abort 'src parameter was not specified' if @src.to_s.empty?
+ raise ImgError, "The 'src' parameter was not specified" if @src.to_s.empty?
@src.gsub('.webp', '.png')
end
def self.local_path?(src)
@@ -76,10 +81,10 @@
private
def setup_src
@src = @src.to_s.strip
- abort 'src parameter was not specified' if @src.empty?
+ raise ImgError, "The 'src' parameter was not specified", [] if @src.empty?
@src = "/assets/images/#{@src}" unless ImgProperties.local_path?(@src) || url?(@src)
end
UNITS = %w[Q ch cm em dvh dvw ex in lh lvh lvw mm pc px pt rem rlh svh svw vb vh vi vmax vmin vw %].freeze