2014-12-08 00:06:28 +11:00
|
|
|
module Jekyll
|
|
|
|
class ResponsiveImage
|
|
|
|
class Block < Liquid::Block
|
|
|
|
def render(context)
|
|
|
|
config = ResponsiveImage.defaults.dup
|
|
|
|
config.merge!(context.registers[:site].config['responsive_image'])
|
|
|
|
|
|
|
|
attributes = YAML.load(super)
|
|
|
|
image_template = attributes['template'] || config['template']
|
|
|
|
|
2014-12-08 09:17:19 +11:00
|
|
|
image = ImageProcessor.process(attributes['path'], config)
|
|
|
|
attributes['original'] = image[:original]
|
|
|
|
attributes['resized'] = image[:resized]
|
2014-12-08 00:06:28 +11:00
|
|
|
|
|
|
|
partial = File.read(image_template)
|
|
|
|
template = Liquid::Template.parse(partial)
|
|
|
|
|
|
|
|
template.render!(attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|