Allow template to be overwritten on per-tag basis
This commit is contained in:
parent
320e3955dd
commit
c78b568ecb
|
@ -46,7 +46,13 @@ Replace your images with the `responsive_image` tag, specifying a path to the im
|
||||||
{% responsive_image path: assets/my-file.jpg %}
|
{% responsive_image path: assets/my-file.jpg %}
|
||||||
```
|
```
|
||||||
|
|
||||||
Any extra attributes will be passed to the template.
|
You can override the template on a per-image basis by specifying the `template` attribute.
|
||||||
|
|
||||||
|
```
|
||||||
|
{% responsive_image path: assets/my-file.jpg template: _includes/another-template.html %}
|
||||||
|
```
|
||||||
|
|
||||||
|
Any extra attributes will be passed straight to the template as variables.
|
||||||
|
|
||||||
```
|
```
|
||||||
{% responsive_image path: assets/image.jpg alt: "Lorem ipsum..." title: "Lorem ipsum..." %}
|
{% responsive_image path: assets/image.jpg alt: "Lorem ipsum..." title: "Lorem ipsum..." %}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
{{ resized | map: 'width' }}
|
|
@ -57,3 +57,18 @@ Feature: Jekyll responsive-image tag
|
||||||
And I should see "/assets/resized/test-200x100.png 200w" in "_site/index.html"
|
And I should see "/assets/resized/test-200x100.png 200w" in "_site/index.html"
|
||||||
And the file "assets/resized/test-100x50.png" should exist
|
And the file "assets/resized/test-100x50.png" should exist
|
||||||
And the file "assets/resized/test-200x100.png" should exist
|
And the file "assets/resized/test-200x100.png" should exist
|
||||||
|
|
||||||
|
Scenario: Overriding the template
|
||||||
|
Given I have a responsive_image configuration with:
|
||||||
|
"""
|
||||||
|
template: _includes/responsive-image.html
|
||||||
|
sizes:
|
||||||
|
- width: 100
|
||||||
|
- width: 200
|
||||||
|
"""
|
||||||
|
And I have a file "index.html" with:
|
||||||
|
"""
|
||||||
|
{% responsive_image path: assets/test.png template: _includes/custom-template.html %}
|
||||||
|
"""
|
||||||
|
When I run Jekyll
|
||||||
|
Then I should see "100200" in "_site/index.html"
|
||||||
|
|
|
@ -86,9 +86,10 @@ module Jekyll
|
||||||
config['output_dir'] ||= 'assets/resized'
|
config['output_dir'] ||= 'assets/resized'
|
||||||
config['sizes'] ||= []
|
config['sizes'] ||= []
|
||||||
|
|
||||||
|
@attributes['template'] ||= config['template']
|
||||||
@attributes['resized'] = resize_image(@attributes['path'], config)
|
@attributes['resized'] = resize_image(@attributes['path'], config)
|
||||||
|
|
||||||
partial = File.read(config['template'])
|
partial = File.read(@attributes['template'])
|
||||||
template = Liquid::Template.parse(partial)
|
template = Liquid::Template.parse(partial)
|
||||||
|
|
||||||
template.render!(@attributes)
|
template.render!(@attributes)
|
||||||
|
|
Loading…
Reference in New Issue