Permalink
Browse files

allow the user to set config attr to use included modernizr build

  • Loading branch information...
1 parent e90b08e commit 883168ef36ec66ab28258e2449f2f9d2f12ff941 @matthewrobertson committed Jan 29, 2013
View
@@ -26,6 +26,10 @@ def alternate_versions
category_collection.alternate_versions
end
+ def include_modernizr?
+ category_collection.include_modernizr
+ end
+
def configure
yield(category_collection)
end
@@ -2,6 +2,7 @@ module Ress
class CategoryCollection
+ attr_accessor :include_modernizr
attr_reader :canonical_version, :alternate_versions
def initialize
View
@@ -4,14 +4,21 @@ module ViewHelpers
def ress_annotation_tags
path = "#{request.host_with_port}#{request.fullpath}"
- if canonical_request?
+ html = if canonical_request?
Ress.alternate_versions.map do |category|
category.link_tag(request.protocol, path, self)
- end.join.html_safe
+ end.join
else
Ress.canonical_version.link_tag(request.protocol, path, request.subdomain, self)
end
+ # Append the modernizr script tag if need be.
+ if Ress.include_modernizr?
+ html << self.javascript_include_tag("ress_modernizr_build")
+ end
+
+ html.html_safe
+
end
end
@@ -37,4 +37,16 @@
end
+ describe '#include_modernizr' do
+
+ it 'is false by default' do
+ collection.include_modernizr.should be_false
+ end
+
+ it 'can be set' do
+ collection.include_modernizr = true
+ collection.include_modernizr.should be_true
+ end
+ end
+
end
@@ -10,7 +10,10 @@
let(:category) { Ress::AlternateVersion.new('m', 'stuff') }
before do
- view.stub(:request => request)
+ view.stub(
+ :request => request,
+ :javascript_include_tag => '<script src="/assets/ress_modernizr_build.js" type="text/javascript"></script>'.html_safe
+ )
end
context 'alternate request' do
@@ -21,6 +24,12 @@
view.ress_annotation_tags.should == "<link href=\"http://foo.com/bar\" rel=\"canonical\" />"
end
+ it 'adds a script tag for Modernizr if required' do
+ Ress.stub(:include_modernizr? => true)
+ view.ress_annotation_tags.should ==
+ "<link href=\"http://foo.com/bar\" rel=\"canonical\" /><script src=\"/assets/ress_modernizr_build.js\" type=\"text/javascript\"></script>"
+ end
+
end
context 'canonical request' do
View
@@ -35,4 +35,20 @@
end
+ describe '.include_modernizr?' do
+
+ it 'defaults to false' do
+ Ress.include_modernizr?.should be_false
+ end
+
+ it 'can be altered through Ress.configure' do
+ Ress.configure { |r| r.include_modernizr = true }
+ Ress.include_modernizr?.should be_true
+
+ Ress.configure { |r| r.include_modernizr = false }
+ Ress.include_modernizr?.should be_false
+ end
+
+ end
+
end

0 comments on commit 883168e

Please sign in to comment.