Add cukes
This commit is contained in:
parent
a09d47b60a
commit
fb6ef53a97
|
@ -1,5 +1,5 @@
|
||||||
<img alt="{{ alt }}" src="/{{ path }}" {% if resized %}srcset="
|
<img alt="{{ alt }}" src="/{{ path }}"{% if resized %} srcset="
|
||||||
{% for i in resized %}
|
{% for i in resized %}
|
||||||
/{{ i.path }} {{ i.width }}w{% if forloop.last == false %},{% endif %}
|
/{{ i.path }} {{ i.width }}w{% if forloop.last == false %},{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
" {% endif %}>
|
"{% endif %}>
|
Binary file not shown.
After Width: | Height: | Size: 18 KiB |
|
@ -10,7 +10,38 @@ Feature: Jekyll responsive-image tag
|
||||||
"""
|
"""
|
||||||
And I have a file "index.html" with:
|
And I have a file "index.html" with:
|
||||||
"""
|
"""
|
||||||
{% responsive_image path: assets/test.jpg %}
|
{% responsive_image path: assets/test.png alt: Foobar %}
|
||||||
"""
|
"""
|
||||||
When I run Jekyll
|
When I run Jekyll
|
||||||
Then I should see "<img src=\"/assets/test.jpg\" alt=\"\">" in "_site/index.html"
|
Then I should see "<img alt=\"Foobar\" src=\"/assets/test.png\">" in "_site/index.html"
|
||||||
|
|
||||||
|
Scenario: UTF-8 alt attribute
|
||||||
|
Given I have a responsive_image configuration with:
|
||||||
|
"""
|
||||||
|
template: _includes/responsive-image.html
|
||||||
|
"""
|
||||||
|
And I have a file "index.html" with:
|
||||||
|
"""
|
||||||
|
{% responsive_image path: assets/test.png alt: "かっこいい! ジェケルが好きです!" %}
|
||||||
|
"""
|
||||||
|
When I run Jekyll
|
||||||
|
Then I should see "<img alt=\"かっこいい! ジェケルが好きです!\" src=\"/assets/test.png\">" in "_site/index.html"
|
||||||
|
|
||||||
|
Scenario: Image with multiple sizes
|
||||||
|
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 %}
|
||||||
|
"""
|
||||||
|
When I run Jekyll
|
||||||
|
Then I should see "<img alt=\"\" src=\"/assets/test.png\"" in "_site/index.html"
|
||||||
|
And I should see "/assets/resized/test-100x50.png 100w" 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-200x100.png" should exist
|
||||||
|
|
|
@ -6,14 +6,18 @@ Given /^I have a responsive_image configuration with:$/ do |config|
|
||||||
write_file('_config.yml', "responsive_image:\n#{config}")
|
write_file('_config.yml', "responsive_image:\n#{config}")
|
||||||
end
|
end
|
||||||
|
|
||||||
Given /^I have a file "([^\"]+)" with:$/ do |path, contents|
|
Given /^I have a file "(.+)" with:$/ do |path, contents|
|
||||||
write_file(path, contents)
|
write_file(path, "---\n---\n#{contents}")
|
||||||
end
|
end
|
||||||
|
|
||||||
Then /^I should see "(.*)" in "(.*)"$/ do |text, file|
|
Then /^I should see "(.+)" in "(.*)"$/ do |text, file|
|
||||||
assert_match(Regexp.new(text), File.open(file).readlines.join)
|
assert_match(Regexp.new(text), File.open(file).readlines.join)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Then /^the file "(.+)" should exist$/ do |path|
|
||||||
|
assert File.exists?(path)
|
||||||
|
end
|
||||||
|
|
||||||
def write_file(path, contents)
|
def write_file(path, contents)
|
||||||
File.open(path, 'w') do |f|
|
File.open(path, 'w') do |f|
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
Before do
|
Before do
|
||||||
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
|
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
|
||||||
FileUtils.mkdir_p(TEST_DIR)
|
FileUtils.mkdir_p(TEST_DIR)
|
||||||
|
|
||||||
|
fixtures = File.expand_path('../../fixtures', __FILE__)
|
||||||
|
FileUtils.cp_r(Dir.glob("#{fixtures}/*"), TEST_DIR)
|
||||||
|
|
||||||
Dir.chdir(TEST_DIR)
|
Dir.chdir(TEST_DIR)
|
||||||
end
|
end
|
||||||
|
|
||||||
After do
|
at_exit do
|
||||||
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
|
FileUtils.rm_rf(TEST_DIR) if File.exist?(TEST_DIR)
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,13 +19,17 @@ module Jekyll
|
||||||
end
|
end
|
||||||
|
|
||||||
def resize_image(path, config)
|
def resize_image(path, config)
|
||||||
|
sizes = config['sizes']
|
||||||
|
|
||||||
|
return if sizes.empty?
|
||||||
|
|
||||||
output_dir = config['output_dir']
|
output_dir = config['output_dir']
|
||||||
ensure_output_dir_exists!(output_dir)
|
ensure_output_dir_exists!(output_dir)
|
||||||
|
|
||||||
resized = []
|
resized = []
|
||||||
img = Magick::Image::read(path).first
|
img = Magick::Image::read(path).first
|
||||||
|
|
||||||
config['sizes'].each do |size|
|
sizes.each do |size|
|
||||||
width = size['width']
|
width = size['width']
|
||||||
ratio = width.to_f / img.columns.to_f
|
ratio = width.to_f / img.columns.to_f
|
||||||
height = (img.rows.to_f * ratio).round
|
height = (img.rows.to_f * ratio).round
|
||||||
|
|
Loading…
Reference in New Issue