Module: Jekyll::Imgwh::Helpers
- Included in:
- Jekyll::Imgwh, Tag
- Defined in:
- lib/jekyll/imgwh/helpers.rb
Instance Method Summary collapse
- #debug(*messages) ⇒ Object
- #image_size(src, context) ⇒ Object
- #name ⇒ Object
- #resolve_path(path, context) ⇒ Object
Instance Method Details
#debug(*messages) ⇒ Object
15 16 17 |
# File 'lib/jekyll/imgwh/helpers.rb', line 15 def debug(*) .each { || Jekyll.logger.debug "#{name}:", } end |
#image_size(src, context) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll/imgwh/helpers.rb', line 19 def image_size(src, context) uri = URI(src) if uri.scheme.nil? src = resolve_path(CGI.unescape(uri.path), context) else allowed_schemes = context.registers[:site].config.dig(name, "allowed_schemes") || [] unless allowed_schemes.include?(uri.scheme) raise ArgumentError, "#{name}: URIs with '#{uri.scheme}' scheme are not allowed" end end FastImage.size(src) or raise LoadError, "#{name}: could not get size of image '#{src}'" end |
#name ⇒ Object
11 12 13 |
# File 'lib/jekyll/imgwh/helpers.rb', line 11 def name "imgwh" end |
#resolve_path(path, context) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll/imgwh/helpers.rb', line 34 def resolve_path(path, context) local_path = path.start_with?("/") ? path : File.join(context.registers[:page]["dir"], path) local_path = context.registers[:site].in_source_dir(local_path) debug "image path: '#{local_path}'" return local_path if File.file?(local_path) themed_path = context.registers[:site].in_theme_dir(path) if path.start_with?("/") raise LoadError, "#{name}: '#{local_path}' could not be found" unless themed_path debug "themed image path: '#{themed_path}'" return themed_path if File.file?(themed_path) raise LoadError, "#{name}: none of '#{local_path}', '#{themed_path}' could be found" end |