include Utils rather than calling static methods
This commit is contained in:
parent
d0ee161aa2
commit
4112992565
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue