Added theme_image_tag liquid tag to make it easy to insert theme image files

This commit is contained in:
karlbright 2011-02-15 15:33:52 +08:00
parent 083debc516
commit 9d11d9e019
2 changed files with 18 additions and 0 deletions

View File

@ -38,6 +38,16 @@ module Locomotive
asset_url(input)
end
# Write a theme image tag
# input: name of file including folder
# example: 'about/myphoto.jpg' | theme_image # <img src="images/about/myphoto.jpg" />
def theme_image_tag(input, *args)
return '' if input.nil?
input = "images/#{input}" unless input.starts_with?('/')
image_options = inline_options(args_to_options(args))
"<img src=\"#{asset_url(input)}\" #{image_options}/>"
end
# Write an image tag
# input: url of the image OR asset drop

View File

@ -44,6 +44,14 @@ describe Locomotive::Liquid::Filters::Html do
javascript_tag('/trash/main.js').should == result
javascript_tag('/trash/main').should == result
end
it 'should return an image tag for a given theme file without parameters' do
theme_image_tag('foo.jpg').should == "<img src=\"/sites/000000000000000000000042/theme/images/foo.jpg\" />"
end
it 'should return an image tag for a given theme file with size' do
theme_image_tag('foo.jpg', 'width:100', 'height:100').should == "<img src=\"/sites/000000000000000000000042/theme/images/foo.jpg\" height=\"100\" width=\"100\" />"
end
it 'should return an image tag without parameters' do
image_tag('foo.jpg').should == "<img src=\"foo.jpg\" />"