ress 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -114,7 +114,14 @@ URL of the tablet site, you can load `http://tablet.foo.com/?force=1`.
114
114
 
115
115
  ### Dependencies
116
116
 
117
- TODO: Document Modernizr Dependency
117
+ There are a couple of Modernizr features that must be included in order for
118
+ Ress's javascript feature detection to function. If you are not already
119
+ using Modernizr in your application you can automatically include a build that
120
+ has been packaged with the gem by setting `config.include_modernizr = true` in
121
+ `config/initializers/ress.rb`. If you include your own build (recommended),
122
+ make sure that it includes "Touch Events" and "Media Queries", eg:
123
+
124
+ http://modernizr.com/download/#-touch-mq-teststyles-prefixes
118
125
 
119
126
  ## Performance considerations
120
127
 
@@ -127,7 +134,7 @@ ress.js script and do your own server-side UA-based pushing.
127
134
 
128
135
  ## Browser support
129
136
 
130
- Device.js should work in all browsers that support
137
+ The feature detection javascript should work in all browsers that support
131
138
  `document.querySelectorAll`. Notably, this excludes IE7. If you want it
132
139
  to work in IE7 and below, please include a [polyfill](https://gist.github.com/2724353).
133
140
 
@@ -141,4 +148,4 @@ in a pull request.
141
148
  2. Create your feature branch (`git checkout -b my-new-feature`)
142
149
  3. Commit your changes (`git commit -am 'Add some feature'`)
143
150
  4. Push to the branch (`git push origin my-new-feature`)
144
- 5. Create new Pull Request
151
+ 5. Create new Pull Request
@@ -1,4 +1,67 @@
1
+ # Use this file to configure alternate versions of your application. Be sure to
2
+ # restart your server whenever you make changes.
1
3
  Ress.configure do |config|
2
4
 
3
5
 
6
+ # == Canonical Subdomain
7
+ #
8
+ # If the cannonical version of your application is served under a subdomain
9
+ # you must set it here:
10
+ #
11
+ # config.set_canonical :subdomain => "subdomain"
12
+
13
+
14
+ # == Modernizr
15
+ #
16
+ # There are a couple of Modernizr features that must be included in order for
17
+ # Ress's javascript feature detection to function. If you are not already
18
+ # using Modernizr in your app you can automatically include a build that has
19
+ # been packaged with the gem by setting the below flag to true. If you include
20
+ # your own build (recommended), ensure that you include "Touch Events" and
21
+ # "Media Queries", eg:
22
+ #
23
+ # http://modernizr.com/download/#-touch-mq-teststyles-prefixes
24
+ #
25
+ # config.include_modernizr = false
26
+
27
+
28
+ # == Adding Alternate Site Versions
29
+ #
30
+ # You can register multiple alternate versions of your app by making calls to
31
+ # "config.add_alternate". For example:
32
+ #
33
+ # The following will add an alternate version served under
34
+ # "mobile.your_domain.com" and redirect devices with screens smaller than
35
+ # 640px wide to that version. On the server, it will prepend
36
+ # "app/mobile_views" to the view_paths, so templates there will take
37
+ # precedence over those in "app/views" and add `mobile_request?` controller /
38
+ # helper method to your application.
39
+ #
40
+ # config.add_alternate({
41
+ # :name => 'mobile',
42
+ # :media => 'only screen and (max-width: 640px)'
43
+ # })
44
+ #
45
+ # You can configure the subdomain of a version by passing the ":subdomain"
46
+ # option to "add_alternate". For example, the below will serve the mobile
47
+ # version under "m.your_domain.com" but will still call the controller /
48
+ # helper method `mobile_request?` and prepend "app/mobile_views" to the
49
+ # view_paths
50
+ #
51
+ # config.add_alternate({
52
+ # :name => 'mobile',
53
+ # :media => 'only screen and (max-width: 640px)',
54
+ # :subdomain => 'm'
55
+ # })
56
+ #
57
+ # By default the view_path added for a version is generated from the version
58
+ # name "app/#{name}_views". You may change this path by passing the
59
+ # ":view_path" option, eg:
60
+ #
61
+ # config.add_alternate({
62
+ # :name => 'mobile',
63
+ # :media => 'only screen and (max-width: 640px)',
64
+ # :view_path => Rails.root.join('lib', 'mobile_views')
65
+ # })
66
+
4
67
  end
data/lib/ress.rb CHANGED
@@ -26,6 +26,10 @@ module Ress
26
26
  category_collection.alternate_versions
27
27
  end
28
28
 
29
+ def include_modernizr?
30
+ category_collection.include_modernizr
31
+ end
32
+
29
33
  def configure
30
34
  yield(category_collection)
31
35
  end
@@ -2,6 +2,7 @@ module Ress
2
2
 
3
3
  class CategoryCollection
4
4
 
5
+ attr_accessor :include_modernizr
5
6
  attr_reader :canonical_version, :alternate_versions
6
7
 
7
8
  def initialize
@@ -15,9 +16,20 @@ module Ress
15
16
 
16
17
  def add_alternate(options)
17
18
  version = AlternateVersion.new(options.delete(:name), options.delete(:media), options)
19
+ define_helper_method(version) if defined? ActionController::Base
18
20
  alternate_versions << version
19
21
  end
20
22
 
23
+ private
24
+
25
+ def define_helper_method(version)
26
+ method_name = "#{version.name}_request?".to_sym
27
+ ActionController::Base.send(:define_method, method_name) do
28
+ version.matches?(request.subdomain)
29
+ end
30
+ ActionController::Base.helper_method(method_name)
31
+ end
32
+
21
33
  end
22
34
 
23
35
  end
@@ -2,12 +2,8 @@ module Ress
2
2
 
3
3
  # This module is automatically included into all controllers.
4
4
  module ControllerAdditions
5
- module ClassMethods
6
- # class methods go here
7
- end
8
5
 
9
6
  def self.included(base)
10
- base.extend ClassMethods
11
7
  base.helper_method :canonical_request?
12
8
  base.before_filter :prepend_category_view_path
13
9
  end
data/lib/ress/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ress
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -4,14 +4,21 @@ module Ress
4
4
 
5
5
  def ress_annotation_tags
6
6
  path = "#{request.host_with_port}#{request.fullpath}"
7
- if canonical_request?
7
+ html = if canonical_request?
8
8
  Ress.alternate_versions.map do |category|
9
9
  category.link_tag(request.protocol, path, self)
10
- end.join.html_safe
10
+ end.join
11
11
  else
12
12
  Ress.canonical_version.link_tag(request.protocol, path, request.subdomain, self)
13
13
  end
14
14
 
15
+ # Append the modernizr script tag if need be.
16
+ if Ress.include_modernizr?
17
+ html << self.javascript_include_tag("ress_modernizr_build")
18
+ end
19
+
20
+ html.html_safe
21
+
15
22
  end
16
23
 
17
24
  end
@@ -37,4 +37,16 @@ describe Ress::CategoryCollection do
37
37
 
38
38
  end
39
39
 
40
+ describe '#include_modernizr' do
41
+
42
+ it 'is false by default' do
43
+ collection.include_modernizr.should be_false
44
+ end
45
+
46
+ it 'can be set' do
47
+ collection.include_modernizr = true
48
+ collection.include_modernizr.should be_true
49
+ end
50
+ end
51
+
40
52
  end
@@ -10,7 +10,10 @@ describe ActionView::Base do
10
10
  let(:category) { Ress::AlternateVersion.new('m', 'stuff') }
11
11
 
12
12
  before do
13
- view.stub(:request => request)
13
+ view.stub(
14
+ :request => request,
15
+ :javascript_include_tag => '<script src="/assets/ress_modernizr_build.js" type="text/javascript"></script>'.html_safe
16
+ )
14
17
  end
15
18
 
16
19
  context 'alternate request' do
@@ -21,6 +24,12 @@ describe ActionView::Base do
21
24
  view.ress_annotation_tags.should == "<link href=\"http://foo.com/bar\" rel=\"canonical\" />"
22
25
  end
23
26
 
27
+ it 'adds a script tag for Modernizr if required' do
28
+ Ress.stub(:include_modernizr? => true)
29
+ view.ress_annotation_tags.should ==
30
+ "<link href=\"http://foo.com/bar\" rel=\"canonical\" /><script src=\"/assets/ress_modernizr_build.js\" type=\"text/javascript\"></script>"
31
+ end
32
+
24
33
  end
25
34
 
26
35
  context 'canonical request' do
data/spec/ress_spec.rb CHANGED
@@ -35,4 +35,20 @@ describe Ress do
35
35
 
36
36
  end
37
37
 
38
+ describe '.include_modernizr?' do
39
+
40
+ it 'defaults to false' do
41
+ Ress.include_modernizr?.should be_false
42
+ end
43
+
44
+ it 'can be altered through Ress.configure' do
45
+ Ress.configure { |r| r.include_modernizr = true }
46
+ Ress.include_modernizr?.should be_true
47
+
48
+ Ress.configure { |r| r.include_modernizr = false }
49
+ Ress.include_modernizr?.should be_false
50
+ end
51
+
52
+ end
53
+
38
54
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ress
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.0.4
4
5
  prerelease:
5
- version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthew Robertson
@@ -12,32 +12,32 @@ cert_chain: []
12
12
  date: 2013-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- version_requirements: !ruby/object:Gem::Requirement
15
+ name: actionpack
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
16
18
  requirements:
17
19
  - - ~>
18
20
  - !ruby/object:Gem::Version
19
21
  version: '3.0'
20
22
  none: false
21
- name: actionpack
22
23
  type: :runtime
23
- prerelease: false
24
- requirement: !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - ~>
27
27
  - !ruby/object:Gem::Version
28
28
  version: '3.0'
29
29
  none: false
30
30
  - !ruby/object:Gem::Dependency
31
- version_requirements: !ruby/object:Gem::Requirement
31
+ name: rspec
32
+ prerelease: false
33
+ requirement: !ruby/object:Gem::Requirement
32
34
  requirements:
33
35
  - - ! '>='
34
36
  - !ruby/object:Gem::Version
35
37
  version: '0'
36
38
  none: false
37
- name: rspec
38
39
  type: :development
39
- prerelease: false
40
- requirement: !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ! '>='
43
43
  - !ruby/object:Gem::Version
@@ -74,8 +74,8 @@ files:
74
74
  - spec/ress/controller_additions_spec.rb
75
75
  - spec/ress/view_helpers_spec.rb
76
76
  - spec/ress_spec.rb
77
- - vendor/assets/javascripts/modernizr.js
78
77
  - vendor/assets/javascripts/ress.js
78
+ - vendor/assets/javascripts/ress_modernizr_build.js
79
79
  homepage: https://github.com/matthewrobertson/ress
80
80
  licenses: []
81
81
  post_install_message: