Skip to content
Browse files

Merge branch 'master' of github.com:matthewrobertson/ress

  • Loading branch information...
2 parents c6de025 + 5aeb96f commit 03b8ccff2934ed36cc4654e2d4263849ecf948ff @matthewrobertson committed Jan 29, 2013
View
52 lib/generators/ress/templates/ress.rb
@@ -1,26 +1,24 @@
-# Use this file to configure alternate versions of your
-# application. Be sure to restart your server whenever
-# you make changes.
+# Use this file to configure alternate versions of your application. Be sure to
+# restart your server whenever you make changes.
Ress.configure do |config|
# == Canonical Subdomain
#
- # If the cannonical version of your application is served
- # under a subdomain you must set it here:
+ # If the cannonical version of your application is served under a subdomain
+ # you must set it here:
#
# config.set_canonical :subdomain => "subdomain"
# == Modernizr
#
- # There are a couple of Modernizr features that must be
- # included in order for Ress's javascript feature detection
- # to function. If you are not already using Modernizr in
- # your app you can automatically include a build that has
- # been packaged with the gem by setting the below flag to
- # true. If you include your own build (recommended), ensure
- # that you include "Touch Events" and "Media Queries", eg:
+ # There are a couple of Modernizr features that must be included in order for
+ # Ress's javascript feature detection to function. If you are not already
+ # using Modernizr in your app you can automatically include a build that has
+ # been packaged with the gem by setting the below flag to true. If you include
+ # your own build (recommended), ensure that you include "Touch Events" and
+ # "Media Queries", eg:
#
# http://modernizr.com/download/#-touch-mq-teststyles-prefixes
#
@@ -29,36 +27,36 @@
# == Adding Alternate Site Versions
#
- # You can register multiple alternate versions of your app
- # by making calls to "config.add_alternate". For example:
+ # You can register multiple alternate versions of your app by making calls to
+ # "config.add_alternate". For example:
#
# The following will add an alternate version served under
- # "mobile.your_domain.com" and redirect devices with screens
- # smaller than 640px wide to that version. On the server, it
- # will prepend "app/mobile_views" to the view_paths, so templates
- # there will take precedence over those in "app/views" and add
- # `mobile_request?` controller / helper method to your application.
+ # "mobile.your_domain.com" and redirect devices with screens smaller than
+ # 640px wide to that version. On the server, it will prepend
+ # "app/mobile_views" to the view_paths, so templates there will take
+ # precedence over those in "app/views" and add `mobile_request?` controller /
+ # helper method to your application.
#
# config.add_alternate({
# :name => 'mobile',
# :media => 'only screen and (max-width: 640px)'
# })
#
- # You can configure the subdomain of a version by passing
- # the ":subdomain" option to "add_alternate". For example,
- # the below will serve the mobile version under "m.your_domain.com"
- # but will still call the controller / helper method
- # `mobile_request?` and prepend "app/mobile_views" to the view_paths
+ # You can configure the subdomain of a version by passing the ":subdomain"
+ # option to "add_alternate". For example, the below will serve the mobile
+ # version under "m.your_domain.com" but will still call the controller /
+ # helper method `mobile_request?` and prepend "app/mobile_views" to the
+ # view_paths
#
# config.add_alternate({
# :name => 'mobile',
# :media => 'only screen and (max-width: 640px)',
# :subdomain => 'm'
# })
#
- # By default the view_path added for a version is generated from
- # the version name "app/#{name}_views". You may change this path
- # by passing the ":view_path" option, eg:
+ # By default the view_path added for a version is generated from the version
+ # name "app/#{name}_views". You may change this path by passing the
+ # ":view_path" option, eg:
#
# config.add_alternate({
# :name => 'mobile',
View
4 lib/ress.rb
@@ -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
View
12 lib/ress/category_collection.rb
@@ -2,6 +2,7 @@ module Ress
class CategoryCollection
+ attr_accessor :include_modernizr
attr_reader :canonical_version, :alternate_versions
def initialize
@@ -15,9 +16,20 @@ def set_canonical(options = {})
def add_alternate(options)
version = AlternateVersion.new(options.delete(:name), options.delete(:media), options)
+ define_helper_method(version) if defined? ActionController::Base
alternate_versions << version
end
+ private
+
+ def define_helper_method(version)
+ method_name = "#{version.name}_request?".to_sym
+ ActionController::Base.send(:define_method, method_name) do
+ version.matches?(request.subdomain)
+ end
+ ActionController::Base.helper_method(method_name)
+ end
+
end
end
View
4 lib/ress/controller_additions.rb
@@ -2,12 +2,8 @@ module Ress
# This module is automatically included into all controllers.
module ControllerAdditions
- module ClassMethods
- # class methods go here
- end
def self.included(base)
- base.extend ClassMethods
base.helper_method :canonical_request?
base.helper_method :force_canonical_url
base.before_filter :prepend_category_view_path
View
2 lib/ress/version.rb
@@ -1,3 +1,3 @@
module Ress
- VERSION = "0.0.3"
+ VERSION = "0.0.4"
end
View
11 lib/ress/view_helpers.rb
@@ -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
View
12 spec/ress/category_collection_spec.rb
@@ -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
View
11 spec/ress/view_helpers_spec.rb
@@ -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
16 spec/ress_spec.rb
@@ -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
View
0 vendor/assets/javascripts/modernizr.js → ...ssets/javascripts/ress_modernizr_build.js
File renamed without changes.

0 comments on commit 03b8ccf

Please sign in to comment.
Something went wrong with that request. Please try again.