Module: Jekyll::ResponsiveImage::Utils
- Included in:
- Common, ImageProcessor, ResizeHandler
- Defined in:
- lib/jekyll/responsive_image/utils.rb
Instance Method Summary collapse
- #format_output_path(format, base_path, image_path, width, height) ⇒ Object
-
#image_hash(base_path, image_path, width, height) ⇒ Object
Build a hash containing image information.
- #relative_dirname(base_path, image_path) ⇒ Object
- #symbolize_keys(hash) ⇒ Object
Instance Method Details
#format_output_path(format, base_path, image_path, width, height) ⇒ Object
14 15 16 17 18 |
# File 'lib/jekyll/responsive_image/utils.rb', line 14 def format_output_path(format, base_path, image_path, width, height) params = symbolize_keys(image_hash(base_path, image_path, width, height)) Pathname.new(format % params).cleanpath.to_s end |
#image_hash(base_path, image_path, width, height) ⇒ Object
Build a hash containing image information
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/jekyll/responsive_image/utils.rb', line 21 def image_hash(base_path, image_path, width, height) { 'path' => image_path, 'dirname' => relative_dirname(base_path, image_path), 'basename' => File.basename(image_path), 'filename' => File.basename(image_path, '.*'), 'extension' => File.extname(image_path).delete('.'), 'width' => width, 'height' => height, } end |
#relative_dirname(base_path, image_path) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/jekyll/responsive_image/utils.rb', line 33 def relative_dirname(base_path, image_path) path = Pathname.new(image_path). base = Pathname.new(base_path). path.relative_path_from(base).dirname.to_s.delete('.') end |
#symbolize_keys(hash) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/jekyll/responsive_image/utils.rb', line 6 def symbolize_keys(hash) result = {} hash.each_key do |key| result[key.to_sym] = hash[key] end result end |