This commit is contained in:
Didier Lafforgue 2012-04-20 15:42:10 +02:00
parent fa6e62dd84
commit d6059c2a9b
2 changed files with 13 additions and 5 deletions

View File

@ -7,6 +7,8 @@ module Locomotive
if source.is_a?(String) || source.is_a?(Hash) # simple string or theme asset if source.is_a?(String) || source.is_a?(Hash) # simple string or theme asset
source = source['url'] if source.is_a?(Hash) source = source['url'] if source.is_a?(Hash)
source.strip!
if source =~ /^http/ if source =~ /^http/
file = self.app.fetch_url(source) file = self.app.fetch_url(source)
else else

View File

@ -17,13 +17,19 @@ describe Locomotive::Liquid::Filters::Resize do
@template = Liquid::Template.parse('{{ asset_url | resize: "40x30" }}') @template = Liquid::Template.parse('{{ asset_url | resize: "40x30" }}')
end end
it 'should return the location of the resized image' do it 'returns the location of the resized image' do
@template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/ @template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/
end end
it 'should use the path in the public folder to generate a location' do it 'uses the path in the public folder to generate a location' do
@template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30') @template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30')
end end
it 'accepts strings with leading and trailing empty characters' do
@context['asset_url'] = " \t #{@context['asset_url']} \n\n "
@template.render(@context).should == Locomotive::Dragonfly.resize_url(@asset_path, '40x30')
end
end end
context 'when a theme asset is given' do context 'when a theme asset is given' do
@ -31,11 +37,11 @@ describe Locomotive::Liquid::Filters::Resize do
@template = Liquid::Template.parse("{{ theme_asset | resize: '300x400' }}") @template = Liquid::Template.parse("{{ theme_asset | resize: '300x400' }}")
end end
it 'should return the location of the resized image' do it 'returns the location of the resized image' do
@template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/ @template.render(@context).should =~ /images\/dynamic\/.*\/5k.png/
end end
it 'should use the path of the theme asset to generate a location' do it 'uses the path of the theme asset to generate a location' do
@template.render(@context).should == Locomotive::Dragonfly.resize_url(@theme_asset_path, '300x400') @template.render(@context).should == Locomotive::Dragonfly.resize_url(@theme_asset_path, '300x400')
end end
end end
@ -45,7 +51,7 @@ describe Locomotive::Liquid::Filters::Resize do
@template = Liquid::Template.parse('{{ asset | resize: }}') @template = Liquid::Template.parse('{{ asset | resize: }}')
end end
it 'should return a liquid error' do it 'returns a liquid error' do
@template.render(@context).should include 'Liquid error: wrong number of arguments' @template.render(@context).should include 'Liquid error: wrong number of arguments'
end end
end end