Skip to content

Commit

Permalink
Forgot to allow remote assets. Updated really minor version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Knowlden committed Dec 21, 2008
1 parent c7127a0 commit 4e040c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion chicago.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = "chicago"
s.version = "0.1.2"
s.version = "0.1.2.1"
s.date = "2008-12-05"
s.summary = "Sinatra runtime and testing extensions used commonly by Thumblemonks"
s.email = %w[gus@gusg.us gabriel.gironda@gmail.com]
Expand Down
10 changes: 8 additions & 2 deletions lib/chicago/helpers.rb
Expand Up @@ -8,18 +8,24 @@ def anchor(name, url, options={})
end

def stylesheet_include(name, options={})
defaults = {:href => "/stylesheets/#{name}.css", :media => "screen",
name = "/stylesheets/#{name}.css" unless remote_asset?(name)
defaults = {:href => name, :media => "screen",
:rel => "stylesheet", :type => "text/css"}
options_str = hash_to_attributes(defaults.merge(options))
%Q[<link #{options_str}/>]
end

def javascript_include(name, options={})
defaults = {:src => "/javascripts/#{name}.js", :type => "text/javascript"}
name = "/javascripts/#{name}.js" unless remote_asset?(name)
defaults = {:src => name, :type => "text/javascript"}
options_str = hash_to_attributes(defaults.merge(options))
%Q[<script #{options_str}></script>]
end
private
def remote_asset?(uri)
uri =~ %r[^\w+://.+]
end

def hash_to_attributes(options)
options.map {|k,v| "#{k}=\"#{v}\""}.join(' ')
end
Expand Down
8 changes: 8 additions & 0 deletions test/helpers_test.rb
Expand Up @@ -18,6 +18,10 @@ class HelpersTest < Test::Unit::TestCase
assert_match %r[type="text/css"], @response.body
assert_match %r[baz="boo"], @response.body
end

should_invoke_helper(:stylesheet_include, 'http://example.com') do
assert_match %r[href="http://example.com"], @response.body
end
end # including stylesheets

context "including javascript" do
Expand All @@ -33,6 +37,10 @@ class HelpersTest < Test::Unit::TestCase
assert_match %r[type="text/blarg"], @response.body
assert_match %r[gus="nice"], @response.body
end

should_invoke_helper(:javascript_include, 'http://example.com') do
assert_match %r[src="http://example.com"], @response.body
end
end # including javascript

context "using an anchor" do
Expand Down

0 comments on commit 4e040c0

Please sign in to comment.