Merge pull request #132 from petrblaho/js_css_url
javascript_url and stylesheet_url liquid tag
This commit is contained in:
commit
294da07565
@ -3,9 +3,9 @@ module Locomotive
|
|||||||
module Filters
|
module Filters
|
||||||
module Html
|
module Html
|
||||||
|
|
||||||
# Write the link to a stylesheet resource
|
# Write the url to a stylesheet resource
|
||||||
# input: url of the css file
|
# input: name of the css file
|
||||||
def stylesheet_tag(input, media = 'screen')
|
def stylesheet_url(input)
|
||||||
return '' if input.nil?
|
return '' if input.nil?
|
||||||
|
|
||||||
unless input =~ /^(\/|http:)/
|
unless input =~ /^(\/|http:)/
|
||||||
@ -14,12 +14,22 @@ module Locomotive
|
|||||||
|
|
||||||
input = "#{input}.css" unless input.ends_with?('.css')
|
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)
|
||||||
|
|
||||||
%{<link href="#{input}" media="#{media}" rel="stylesheet" type="text/css" />}
|
%{<link href="#{input}" media="#{media}" rel="stylesheet" type="text/css" />}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Write the link to javascript resource
|
# Write the url to javascript resource
|
||||||
# input: url of the javascript file
|
# input: name of the javascript file
|
||||||
def javascript_tag(input)
|
def javascript_url(input)
|
||||||
return '' if input.nil?
|
return '' if input.nil?
|
||||||
|
|
||||||
unless input =~ /^(\/|http:)/
|
unless input =~ /^(\/|http:)/
|
||||||
@ -28,7 +38,17 @@ module Locomotive
|
|||||||
|
|
||||||
input = "#{input}.js" unless input.ends_with?('.js')
|
input = "#{input}.js" unless input.ends_with?('.js')
|
||||||
|
|
||||||
%{<script src="#{input}" type="text/javascript"></script>}
|
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)
|
||||||
|
|
||||||
|
%{<script src="#{input}" type="text/javascript"></script>}
|
||||||
end
|
end
|
||||||
|
|
||||||
def theme_image_url(input)
|
def theme_image_url(input)
|
||||||
|
@ -8,6 +8,24 @@ describe Locomotive::Liquid::Filters::Html do
|
|||||||
@context = build_context
|
@context = build_context
|
||||||
end
|
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
|
it 'should return a link tag for a stylesheet file' do
|
||||||
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
result = "<link href=\"/sites/000000000000000000000042/theme/stylesheets/main.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />"
|
||||||
stylesheet_tag('main.css').should == result
|
stylesheet_tag('main.css').should == result
|
||||||
@ -44,6 +62,25 @@ describe Locomotive::Liquid::Filters::Html do
|
|||||||
stylesheet_tag('/trash/main','print').should == result
|
stylesheet_tag('/trash/main','print').should == result
|
||||||
end
|
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
|
it 'should return a script tag for a javascript file' do
|
||||||
result = %{<script src="/sites/000000000000000000000042/theme/javascripts/main.js" type="text/javascript"></script>}
|
result = %{<script src="/sites/000000000000000000000042/theme/javascripts/main.js" type="text/javascript"></script>}
|
||||||
javascript_tag('main.js').should == result
|
javascript_tag('main.js').should == result
|
||||||
|
Loading…
Reference in New Issue
Block a user