Module: Jekyll::ResponsiveImage::Utils
- Included in:
- Block, ExtraImageGenerator, ImageProcessor, Renderer, ResizeHandler
- Defined in:
- lib/jekyll-responsive-image/utils.rb
Instance Method Summary collapse
-
#image_hash(config, image_path, width, height) ⇒ Object
Build a hash containing image information.
- #keep_resized_image!(site, image) ⇒ Object
- #relative_dirname(config, image_path) ⇒ Object
- #symbolize_keys(hash) ⇒ Object
Instance Method Details
#image_hash(config, image_path, width, height) ⇒ Object
Build a hash containing image information
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jekyll-responsive-image/utils.rb', line 20 def image_hash(config, image_path, width, height) { 'path' => image_path, 'dirname' => relative_dirname(config, image_path), 'basename' => File.basename(image_path), 'filename' => File.basename(image_path, '.*'), 'extension' => File.extname(image_path).delete('.'), 'width' => width, 'height' => height, } end |
#keep_resized_image!(site, image) ⇒ Object
6 7 8 9 |
# File 'lib/jekyll-responsive-image/utils.rb', line 6 def keep_resized_image!(site, image) keep_dir = File.dirname(image['path']) site.config['keep_files'] << keep_dir unless site.config['keep_files'].include?(keep_dir) end |
#relative_dirname(config, image_path) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/jekyll-responsive-image/utils.rb', line 32 def relative_dirname(config, image_path) path = Pathname.new(File.(image_path, config[:site_source])) base = Pathname.new(File.(config['base_path'], config[:site_source])) path.relative_path_from(base).dirname.to_s.delete('.') end |
#symbolize_keys(hash) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/jekyll-responsive-image/utils.rb', line 11 def symbolize_keys(hash) result = {} hash.each_key do |key| result[key.to_sym] = hash[key] end result end |