lib/img_props.rb in jekyll_img-0.1.6 vs lib/img_props.rb in jekyll_img-0.2.0

- old
+ new

@@ -1,14 +1,12 @@ -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, :attribute, :attribution, :caption, :classes, :continue_on_error, - :id, :img_display, :nofollow, :src, :size, :style, :target, :title, + attr_accessor :align, :alt, :attr_wrapper_align_class, :attribute, :attribution, :caption, :classes, :die_on_img_error, + :id, :img_display, :local_src, :nofollow, :src, :size, :style, :target, :title, :url, :wrapper_class, :wrapper_style SIZES = %w[eighthsize fullsize halfsize initial quartersize].freeze def attr_alt @@ -31,11 +29,11 @@ def attr_size_class return nil if @size == false || @size.nil? || size_unit_specified? unless SIZES.include?(@size) msg = "'#{@size}' is not a recognized size; must be one of #{SIZES.join(', ')}, or an explicit unit." - raise ImgError, msg + raise Jekyll::ImgError, msg end @size end def attr_style_img @@ -67,11 +65,11 @@ @alt ||= @caption || @title @title ||= @caption || @alt end def src_png - raise ImgError, "The 'src' parameter was not specified" if @src.to_s.empty? + raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.to_s.empty? @src.gsub('.webp', '.png') end def self.local_path?(src) @@ -81,15 +79,19 @@ private def setup_src @src = @src.to_s.strip - raise ImgError, "The 'src' parameter was not specified", [] if @src.empty? + raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.empty? filetype = File.extname(URI(@src).path) @src += '.webp' if filetype.empty? @src = "/assets/images/#{@src}" unless ImgProperties.local_path?(@src) || url?(@src) + return unless ImgProperties.local_path?(@src) + + src = @src.start_with?('/') ? ".#{@src}" : @src + raise Jekyll::ImgError, "#{@src} does not exist" unless File.exist?(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 def size_unit_specified?