jekyll-responsive-image/lib/jekyll/responsive_image/block.rb

24 lines
635 B
Ruby
Raw Normal View History

2014-12-08 00:06:28 +11:00
module Jekyll
class ResponsiveImage
class Block < Liquid::Block
include Jekyll::ResponsiveImage::Common
2014-12-08 00:06:28 +11:00
def render(context)
config = make_config(context.registers[:site])
2014-12-08 00:06:28 +11:00
attributes = YAML.load(super)
image_template = attributes['template'] || config['template']
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