lib/img_props.rb in jekyll_img-0.2.6 vs lib/img_props.rb in jekyll_img-0.2.7
- old
+ new
@@ -8,10 +8,11 @@
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
+ 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 attr_alt
"alt='#{@alt}'" if @alt
end
@@ -67,28 +68,22 @@
@alt ||= @caption || @title
@title ||= @caption || @alt
end
def src_any(filetype)
- @src.gsub('.webp', ".#{filetype}")
+ @src.gsub(/\..*?$/, ".#{filetype}")
end
- def src_png
- raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.to_s.empty?
-
- @src.gsub('.webp', '.png')
- end
-
def self.local_path?(src)
first_char = src[0]
first_char.match?(%r{[./]})
end
private
def setup_src
- raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.nil?
+ raise Jekyll::ImgError, "The 'src' parameter was not specified" if @src.nil? || [true, false].include?(@src)
raise Jekyll::ImgError, "The 'src' parameter was empty" if @src.empty?
@src = @src.to_s.strip
raise Jekyll::ImgError, "The 'src' parameter only contained whitespace" if @src.empty?
@@ -100,11 +95,9 @@
# 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?
return false if @size == false || @size.to_s.strip.empty?
@size.end_with?(*UNITS)