From 4112992565ec83a80df4825719f7261fc2108e6d Mon Sep 17 00:00:00 2001 From: Joseph Wynn Date: Sun, 7 Dec 2014 22:03:26 +0000 Subject: [PATCH] include Utils rather than calling static methods --- lib/jekyll/responsive_image/block.rb | 4 +++- lib/jekyll/responsive_image/resize_handler.rb | 6 ++++-- lib/jekyll/responsive_image/tag.rb | 4 +++- lib/jekyll/responsive_image/utils.rb | 6 +++--- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/responsive_image/block.rb b/lib/jekyll/responsive_image/block.rb index dabae5b..d52d73d 100644 --- a/lib/jekyll/responsive_image/block.rb +++ b/lib/jekyll/responsive_image/block.rb @@ -1,6 +1,8 @@ module Jekyll class ResponsiveImage class Block < Liquid::Block + include ResponsiveImage::Utils + def render(context) config = ResponsiveImage.defaults.dup config.merge!(context.registers[:site].config['responsive_image']) @@ -10,7 +12,7 @@ module Jekyll resize_handler = ResizeHandler.new img = Magick::Image::read(attributes['path']).first - attributes['original'] = Utils.image_hash(attributes['path'], img.columns, img.rows) + attributes['original'] = image_hash(attributes['path'], img.columns, img.rows) attributes['resized'] = resize_handler.resize_image(img, config) partial = File.read(image_template) diff --git a/lib/jekyll/responsive_image/resize_handler.rb b/lib/jekyll/responsive_image/resize_handler.rb index 1d8e841..263ab3a 100644 --- a/lib/jekyll/responsive_image/resize_handler.rb +++ b/lib/jekyll/responsive_image/resize_handler.rb @@ -1,6 +1,8 @@ module Jekyll class ResponsiveImage class ResizeHandler + include ResponsiveImage::Utils + def resize_image(img, config) resized = [] @@ -12,7 +14,7 @@ module Jekyll next unless needs_resizing?(img, width) filepath = format_output_path(config['output_path_format'], img.filename, width, height) - resized.push(Utils.image_hash(filepath, width, height)) + resized.push(image_hash(filepath, width, height)) # Don't resize images more than once next if File.exists?(filepath) @@ -33,7 +35,7 @@ module Jekyll end def format_output_path(format, path, width, height) - params = Utils.symbolize_keys(Utils.image_hash(path, width, height)) + params = symbolize_keys(image_hash(path, width, height)) format % params end diff --git a/lib/jekyll/responsive_image/tag.rb b/lib/jekyll/responsive_image/tag.rb index 43856cf..4d6815e 100644 --- a/lib/jekyll/responsive_image/tag.rb +++ b/lib/jekyll/responsive_image/tag.rb @@ -1,6 +1,8 @@ module Jekyll class ResponsiveImage class Tag < Liquid::Tag + include ResponsiveImage::Utils + def initialize(tag_name, markup, tokens) super @@ -18,7 +20,7 @@ module Jekyll resize_handler = ResizeHandler.new img = Magick::Image::read(@attributes['path']).first - @attributes['original'] = Utils.image_hash(@attributes['path'], img.columns, img.rows) + @attributes['original'] = image_hash(@attributes['path'], img.columns, img.rows) @attributes['resized'] = resize_handler.resize_image(img, config) image_template = @attributes['template'] || config['template'] diff --git a/lib/jekyll/responsive_image/utils.rb b/lib/jekyll/responsive_image/utils.rb index a8505c9..425c30c 100644 --- a/lib/jekyll/responsive_image/utils.rb +++ b/lib/jekyll/responsive_image/utils.rb @@ -1,7 +1,7 @@ module Jekyll class ResponsiveImage - class Utils - def self.symbolize_keys(hash) + module Utils + def symbolize_keys(hash) result = {} hash.each_key do |key| result[key.to_sym] = hash[key] @@ -10,7 +10,7 @@ module Jekyll end # Build a hash containing image information - def self.image_hash(path, width, height) + def image_hash(path, width, height) { 'path' => path, 'basename' => File.basename(path),