Fixes bypassing full url when using stylesheet_url liquid filter (fixed #121)

Ivan Youroff committed Oct 07, 2013
commit 7e42f49dc1e89b1181d968b3c13ca0c2fcb50c51
Showing 3 changed files with 15 additions and 5 deletions
locomotive/wagon/liquid/filters/html.rb b/lib/locomotive/wagon/liquid/filters/html.rb +7 -5
@@ @@ -23,11 +23,13 @@ module Locomotive
def stylesheet_url(input)
return '' if input.nil?
- input = "/stylesheets/#{input}" unless input =~ /^(\/|https?:)/
-
- input = "#{input}.css" unless input.ends_with?('.css')
-
- input
+ if input =~ /^https?:/
+ input
+ else
+ input = "/stylesheets/#{input}" unless input =~ /^\//
+ input = "#{input}.css" unless input.ends_with?('.css')
+ input
+ end
end
# Write the link to a stylesheet resource
spec/fixtures/default/app/views/pages/index.liquid.haml +1 -0
@@ @@ -22,6 +22,7 @@ title: Home page
<link href="/fonts/chunkfive.css" media="screen" rel="stylesheet" type="text/css" />
/ Le styles
+ {{ 'http://fonts.googleapis.com/css?family=Open+Sans:400,700' | stylesheet_tag }}
{{ 'reboot' | stylesheet_tag }}
{{ 'application' | stylesheet_tag }}
%script{ :src => "{{ 'application.js' | javascript_url }}", :type => 'text/javascript' }
spec/integration/server/liquid_spec.rb +7 -0
@@ @@ -79,5 +79,12 @@ describe Locomotive::Wagon::Server do
end
end
+
+ describe 'html helpers' do
+ it 'bypass url for css resource' do
+ get '/'
+ last_response.body.should =~ /<link href=("|')http:\/\/fonts\.googleapis\.com\/css\?family=Open\+Sans:400,700("|')/
+ end
+ end
end
\ No newline at end of file