include Utils rather than calling static methods
This commit is contained in:
parent
d0ee161aa2
commit
4112992565
|
@ -1,6 +1,8 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class ResponsiveImage
|
class ResponsiveImage
|
||||||
class Block < Liquid::Block
|
class Block < Liquid::Block
|
||||||
|
include ResponsiveImage::Utils
|
||||||
|
|
||||||
def render(context)
|
def render(context)
|
||||||
config = ResponsiveImage.defaults.dup
|
config = ResponsiveImage.defaults.dup
|
||||||
config.merge!(context.registers[:site].config['responsive_image'])
|
config.merge!(context.registers[:site].config['responsive_image'])
|
||||||
|
@ -10,7 +12,7 @@ module Jekyll
|
||||||
|
|
||||||
resize_handler = ResizeHandler.new
|
resize_handler = ResizeHandler.new
|
||||||
img = Magick::Image::read(attributes['path']).first
|
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)
|
attributes['resized'] = resize_handler.resize_image(img, config)
|
||||||
|
|
||||||
partial = File.read(image_template)
|
partial = File.read(image_template)
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class ResponsiveImage
|
class ResponsiveImage
|
||||||
class ResizeHandler
|
class ResizeHandler
|
||||||
|
include ResponsiveImage::Utils
|
||||||
|
|
||||||
def resize_image(img, config)
|
def resize_image(img, config)
|
||||||
resized = []
|
resized = []
|
||||||
|
|
||||||
|
@ -12,7 +14,7 @@ module Jekyll
|
||||||
next unless needs_resizing?(img, width)
|
next unless needs_resizing?(img, width)
|
||||||
|
|
||||||
filepath = format_output_path(config['output_path_format'], img.filename, width, height)
|
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
|
# Don't resize images more than once
|
||||||
next if File.exists?(filepath)
|
next if File.exists?(filepath)
|
||||||
|
@ -33,7 +35,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_output_path(format, path, width, height)
|
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
|
format % params
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class ResponsiveImage
|
class ResponsiveImage
|
||||||
class Tag < Liquid::Tag
|
class Tag < Liquid::Tag
|
||||||
|
include ResponsiveImage::Utils
|
||||||
|
|
||||||
def initialize(tag_name, markup, tokens)
|
def initialize(tag_name, markup, tokens)
|
||||||
super
|
super
|
||||||
|
|
||||||
|
@ -18,7 +20,7 @@ module Jekyll
|
||||||
|
|
||||||
resize_handler = ResizeHandler.new
|
resize_handler = ResizeHandler.new
|
||||||
img = Magick::Image::read(@attributes['path']).first
|
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)
|
@attributes['resized'] = resize_handler.resize_image(img, config)
|
||||||
|
|
||||||
image_template = @attributes['template'] || config['template']
|
image_template = @attributes['template'] || config['template']
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Jekyll
|
module Jekyll
|
||||||
class ResponsiveImage
|
class ResponsiveImage
|
||||||
class Utils
|
module Utils
|
||||||
def self.symbolize_keys(hash)
|
def symbolize_keys(hash)
|
||||||
result = {}
|
result = {}
|
||||||
hash.each_key do |key|
|
hash.each_key do |key|
|
||||||
result[key.to_sym] = hash[key]
|
result[key.to_sym] = hash[key]
|
||||||
|
@ -10,7 +10,7 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
# Build a hash containing image information
|
# Build a hash containing image information
|
||||||
def self.image_hash(path, width, height)
|
def image_hash(path, width, height)
|
||||||
{
|
{
|
||||||
'path' => path,
|
'path' => path,
|
||||||
'basename' => File.basename(path),
|
'basename' => File.basename(path),
|
||||||
|
|
Loading…
Reference in New Issue