Permalink
Browse files

use protocol relative urls to support https sites

  • Loading branch information...
1 parent 4f72ff0 commit 2d64d7ec891620c3b502d0438de1b9ee6f432000 @phlipper phlipper committed Mar 30, 2012
Showing with 8 additions and 8 deletions.
  1. +4 −4 lib/rack/typekit.rb
  2. +4 −4 spec/rack_typekit_spec.rb
View
@@ -14,7 +14,7 @@ def call(env)
return [@status, @headers, @response] unless html?
response = Rack::Response.new([], @status, @headers)
if @response.respond_to?(:to_ary)
- @response.each { |fragment| response.write inject(fragment) }
+ @response.each { |fragment| response.write inject_typekit(fragment) }
end
response.finish
end
@@ -23,10 +23,10 @@ def call(env)
def html?; @headers["Content-Type"] =~ /html/; end
- def inject(response)
+ def inject_typekit(response)
script = <<-EOF
-<script type="text/javascript" src="http://use.typekit.com/#{@options[:kit]}.js"></script>
-<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
+<script src="//use.typekit.com/#{@options[:kit]}.js"></script>
+<script>try{Typekit.load();}catch(e){}</script>
EOF
response.gsub(%r{</head>}, script + "</head>")
@@ -25,8 +25,8 @@
let(:response) { request.get("/") }
it { response.status.must_equal 200 }
- it { response.body.must_match %(src="http://use.typekit.com/123.js") }
- it { response.body.must_match "try{Typekit.load();}catch(e){}" }
+ it { response.body.must_match %(<script src="//use.typekit.com/123.js"></script>) }
+ it { response.body.must_match "<script>try{Typekit.load();}catch(e){}</script>" }
it { response.body.must_match "<title>Rack::Typekit Test</title>" }
it { response.body.must_match "<p>Test file.</p>" }
end
@@ -36,8 +36,8 @@
let(:response) { request.get("/") }
it { response.status.must_equal 200 }
- it { response.body.wont_match %(src="http://use.typekit.com/123.js") }
- it { response.body.wont_match "try{Typekit.load();}catch(e){}" }
+ it { response.body.wont_match %(<script src="//use.typekit.com/123.js"></script>) }
+ it { response.body.wont_match "<script>try{Typekit.load();}catch(e){}</script>" }
it { response.body.must_match "FOO" }
end
end

0 comments on commit 2d64d7e

Please sign in to comment.