-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from wildlyinaccurate/source-directory-take-2
Take 2 of "treat paths as relative to Jekyll `source` directory"
- Loading branch information
Showing
20 changed files
with
218 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
Feature: Image hashes inside responsive image templates | ||
As a Jekyll user | ||
I want to have access to image hashes | ||
In order to create custom responsive image templates | ||
|
||
Scenario: Using the {% responsive_image %} tag | ||
Given I have a configuration with: | ||
""" | ||
responsive_image: | ||
template: _includes/hash.html | ||
output_path_format: assets/resized/%{dirname}/%{width}/%{basename} | ||
sizes: | ||
- width: 100 | ||
- width: 120 | ||
""" | ||
And I have a file "index.html" with "{% responsive_image path: assets/subdir/test.png %}" | ||
When I run Jekyll | ||
Then the file "_site/index.html" should contain: | ||
""" | ||
path: assets/subdir/test.png | ||
width: 300 | ||
height: 150 | ||
basename: test.png | ||
dirname: subdir | ||
filename: test | ||
extension: png | ||
path: assets/resized/subdir/100/test.png | ||
width: 100 | ||
height: 50 | ||
basename: test.png | ||
dirname: resized/subdir/100 | ||
filename: test | ||
extension: png | ||
path: assets/resized/subdir/120/test.png | ||
width: 120 | ||
height: 60 | ||
basename: test.png | ||
dirname: resized/subdir/120 | ||
filename: test | ||
extension: png | ||
""" | ||
|
||
Scenario: Honouring Jekyll 'source' configuration | ||
Given I have copied my site to "my-site-copy/src" | ||
And I have a configuration with: | ||
""" | ||
source: my-site-copy/src | ||
responsive_image: | ||
template: _includes/hash.html | ||
output_path_format: assets/resized/%{dirname}/%{width}/%{basename} | ||
sizes: | ||
- width: 100 | ||
""" | ||
And I have a file "my-site-copy/src/index.html" with "{% responsive_image path: assets/subdir/test.png %}" | ||
When I run Jekyll | ||
Then the file "_site/index.html" should contain: | ||
""" | ||
path: assets/subdir/test.png | ||
width: 300 | ||
height: 150 | ||
basename: test.png | ||
dirname: subdir | ||
filename: test | ||
extension: png | ||
path: assets/resized/subdir/100/test.png | ||
width: 100 | ||
height: 50 | ||
basename: test.png | ||
dirname: resized/subdir/100 | ||
filename: test | ||
extension: png | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<img src="{{ site.baseurl }}/{{ path }}"> | ||
<img src="{{ site.baseurl }}/{{ original.path }}"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
path: {{ original.path }} | ||
width: {{ original.width }} | ||
height: {{ original.height }} | ||
basename: {{ original.basename }} | ||
dirname: {{ original.dirname }} | ||
filename: {{ original.filename }} | ||
extension: {{ original.extension }} | ||
{% for i in resized %} | ||
path: {{ i.path }} | ||
width: {{ i.width }} | ||
height: {{ i.height }} | ||
basename: {{ i.basename }} | ||
dirname: {{ i.dirname }} | ||
filename: {{ i.filename }} | ||
extension: {{ i.extension }} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<img alt="{{ alt }}" src="/{{ path }}" title="{{ title }}" srcset="{% for i in resized %}/{{ i.path }} {{ i.width }}w,{% endfor %}/{{ original.path }} {{ original.width }}w"> | ||
<img alt="{{ alt }}" src="/{{ original.path }}" title="{{ title }}" srcset="{% for i in resized %}/{{ i.path }} {{ i.width }}w,{% endfor %}/{{ original.path }} {{ original.width }}w"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Jekyll | ||
module ResponsiveImage | ||
class Config | ||
DEFAULTS = { | ||
'default_quality' => 85, | ||
'base_path' => 'assets', | ||
'output_path_format' => 'assets/resized/%{filename}-%{width}x%{height}.%{extension}', | ||
'sizes' => [], | ||
'extra_images' => [] | ||
} | ||
|
||
def initialize(site) | ||
@site = site | ||
end | ||
|
||
def to_h | ||
DEFAULTS.merge(@site.config['responsive_image']) | ||
.merge(site_source: @site.source, site_dest: @site.dest) | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Jekyll | ||
class ResponsiveImage | ||
module ResponsiveImage | ||
class RenderCache | ||
attr_accessor :store | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Jekyll | ||
module ResponsiveImage | ||
class Renderer | ||
include Jekyll::ResponsiveImage::Utils | ||
|
||
def initialize(site, attributes) | ||
@site = site | ||
@attributes = attributes | ||
end | ||
|
||
def render_responsive_image | ||
cache_key = @attributes.to_s | ||
result = @attributes['cache'] ? RenderCache.get(cache_key) : nil | ||
|
||
if result.nil? | ||
config = Config.new(@site).to_h | ||
|
||
image = ImageProcessor.process(@attributes['path'], config) | ||
@attributes['original'] = image[:original] | ||
@attributes['resized'] = image[:resized] | ||
|
||
@attributes['resized'].each { |resized| keep_resized_image!(@site, resized) } | ||
|
||
image_template = @site.in_source_dir(@attributes['template'] || config['template']) | ||
partial = File.read(image_template) | ||
template = Liquid::Template.parse(partial) | ||
|
||
result = template.render!(@attributes.merge(@site.site_payload)) | ||
|
||
RenderCache.set(cache_key, result) | ||
end | ||
|
||
result | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.