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

25 lines
680 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)
site = context.registers[:site]
config = make_config(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.merge(site.site_payload))
2014-12-08 00:06:28 +11:00
end
end
end
end