diff --git a/lib/locomotive/liquid/filters/html.rb b/lib/locomotive/liquid/filters/html.rb
index bbfde7f3..5fdbb027 100644
--- a/lib/locomotive/liquid/filters/html.rb
+++ b/lib/locomotive/liquid/filters/html.rb
@@ -3,9 +3,9 @@ module Locomotive
module Filters
module Html
- # Write the link to a stylesheet resource
- # input: url of the css file
- def stylesheet_tag(input, media = 'screen')
+ # Write the url to a stylesheet resource
+ # input: name of the css file
+ def stylesheet_url(input)
return '' if input.nil?
unless input =~ /^(\/|http:)/
@@ -14,12 +14,22 @@ module Locomotive
input = "#{input}.css" unless input.ends_with?('.css')
+ input
+ end
+
+ # Write the link to a stylesheet resource
+ # input: url of the css file
+ def stylesheet_tag(input, media = 'screen')
+ return '' if input.nil?
+
+ input = stylesheet_url(input)
+
%{}
end
- # Write the link to javascript resource
- # input: url of the javascript file
- def javascript_tag(input)
+ # Write the url to javascript resource
+ # input: name of the javascript file
+ def javascript_url(input)
return '' if input.nil?
unless input =~ /^(\/|http:)/
@@ -28,7 +38,17 @@ module Locomotive
input = "#{input}.js" unless input.ends_with?('.js')
- %{}
+ input
+ end
+
+ # Write the link to javascript resource
+ # input: url of the javascript file
+ def javascript_tag(input)
+ return '' if input.nil?
+
+ input = javascript_url(input)
+
+ %{}
end
def theme_image_url(input)
diff --git a/spec/lib/locomotive/liquid/filters/html_spec.rb b/spec/lib/locomotive/liquid/filters/html_spec.rb
index fe3d545b..c57ca7c9 100644
--- a/spec/lib/locomotive/liquid/filters/html_spec.rb
+++ b/spec/lib/locomotive/liquid/filters/html_spec.rb
@@ -8,6 +8,24 @@ describe Locomotive::Liquid::Filters::Html do
@context = build_context
end
+ it 'should return a url for a stylesheet file' do
+ result = "/sites/000000000000000000000042/theme/stylesheets/main.css"
+ stylesheet_url('main.css').should == result
+ stylesheet_url('main').should == result
+ stylesheet_url(nil).should == ''
+ end
+
+ it 'should return a url for a stylesheet file with folder' do
+ result = "/sites/000000000000000000000042/theme/stylesheets/trash/main.css"
+ stylesheet_url('trash/main.css').should == result
+ end
+
+ it 'should return a url for a stylesheet file without touching the url' do
+ result = "/trash/main.css"
+ stylesheet_url('/trash/main.css').should == result
+ stylesheet_url('/trash/main').should == result
+ end
+
it 'should return a link tag for a stylesheet file' do
result = ""
stylesheet_tag('main.css').should == result
@@ -44,6 +62,25 @@ describe Locomotive::Liquid::Filters::Html do
stylesheet_tag('/trash/main','print').should == result
end
+ it 'should return a url for a javascript file' do
+ result = "/sites/000000000000000000000042/theme/javascripts/main.js"
+ javascript_url('main.js').should == result
+ javascript_url('main').should == result
+ javascript_url(nil).should == ''
+ end
+
+ it 'should return a url for a javascript file with folder' do
+ result = "/sites/000000000000000000000042/theme/javascripts/trash/main.js"
+ javascript_url('trash/main.js').should == result
+ javascript_url('trash/main').should == result
+ end
+
+ it 'should return a url for a javascript file without touching the url' do
+ result = "/trash/main.js"
+ javascript_url('/trash/main.js').should == result
+ javascript_url('/trash/main').should == result
+ end
+
it 'should return a script tag for a javascript file' do
result = %{}
javascript_tag('main.js').should == result