ress 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ integration/
data/README.md CHANGED
@@ -1,13 +1,13 @@
1
- # Ress
1
+ # RESS
2
2
 
3
3
  A system for building mobile optimized Rails applications using semantic,
4
- media query-based device detection and server side progressive enhancement.
4
+ media query-based device detection and server side component optimization.
5
5
 
6
6
  ## Background
7
7
 
8
- Ress is an extension of the [devicejs](https://github.com/borismus/device.js)
8
+ RESS is an extension of the [devicejs](https://github.com/borismus/device.js)
9
9
  library written by [Boris Smus](http://smus.com/). It adds a back end for
10
- adapting server responses based on client side feature detection. Ress allows
10
+ adapting server responses based on client side feature detection. RESS allows
11
11
  you to specify alternate versions of your website, along with media queries
12
12
  for which devices should be redirected to which version.
13
13
 
@@ -15,7 +15,7 @@ for which devices should be redirected to which version.
15
15
 
16
16
  ### HTML Annotations
17
17
 
18
- When you register alternate mobile versions of your website, Ress adds annotations
18
+ When you register alternate mobile versions of your website, RESS adds annotations
19
19
  to the `<head>` of your document that describe where these pages are located and
20
20
  which devices should be redirected to them.
21
21
 
@@ -43,7 +43,7 @@ all of the `[rel="alternate"]` links in your markup, and evalute their media que
43
43
  to determine if there is an alternate version available that matches the client.
44
44
  If there is, the user is redirected to the url for that version.
45
45
 
46
- ### Server Side Components
46
+ ### Server Side Component Optimization
47
47
 
48
48
  Ress allows you to customize how your Rails application responds to mobile requests in
49
49
  two ways:
@@ -123,6 +123,24 @@ make sure that it includes "Touch Events" and "Media Queries", eg:
123
123
 
124
124
  http://modernizr.com/download/#-touch-mq-teststyles-prefixes
125
125
 
126
+ ### Sessions and Cookies
127
+
128
+ In order to share sessions and cookies between the different subdomains used by the
129
+ alternate versions of your app, you need to configure the `:domain` option both in
130
+ the `config/initializers/session_store.rb` and when setting cookies. For more
131
+ information about how this works see this
132
+ [Railscast](http://railscasts.com/episodes/221-subdomains-in-rails-3).
133
+
134
+ ### Development
135
+
136
+ Because RESS uses subdomains, while developing alternate versions you cannot
137
+ load your site via `localhost` or an IP address. If you want to test on
138
+ the same machine you are running your rails app on, you can load it through
139
+ http://lvh.me or install [pow](http://pow.cx/) and set up a `.dev` domain
140
+ for your app. If you need to test on a mobile device you might want to try
141
+ http://xip.io/.
142
+
143
+
126
144
  ## Performance considerations
127
145
 
128
146
  The javascript included by Ress does some checks and will use client-side
@@ -5,10 +5,16 @@ Ress.configure do |config|
5
5
 
6
6
  # == Canonical Subdomain
7
7
  #
8
- # If the cannonical version of your application is served under a subdomain
8
+ # If the canonical version of your application is served under a subdomain
9
9
  # you must set it here:
10
10
  #
11
11
  # config.set_canonical :subdomain => "subdomain"
12
+ #
13
+ # By default, alternate version subdomains are prepended to the canonical url.
14
+ # If you are using a canonical subdomain and you would like it to be replaced
15
+ # by the alternate subdomains, set this option to true:
16
+ #
17
+ # config.replace_canonical_subdomain = false
12
18
 
13
19
 
14
20
  # == Modernizr
data/lib/ress.rb CHANGED
@@ -4,7 +4,7 @@ require "ress/version"
4
4
  require "ress/subdomain"
5
5
  require "ress/alternate_version"
6
6
  require "ress/canonical_version"
7
- require "ress/category_collection"
7
+ require "ress/config"
8
8
  require "ress/controller_additions"
9
9
  require "ress/view_helpers"
10
10
 
@@ -15,24 +15,28 @@ end
15
15
  module Ress
16
16
  extend self
17
17
 
18
- def category_collection
19
- @categories ||= CategoryCollection.new
18
+ def config
19
+ @config ||= Config.new
20
20
  end
21
21
 
22
22
  def canonical_version
23
- category_collection.canonical_version
23
+ config.canonical_version
24
24
  end
25
25
 
26
26
  def alternate_versions
27
- category_collection.alternate_versions
27
+ config.alternate_versions
28
28
  end
29
29
 
30
30
  def include_modernizr?
31
- category_collection.include_modernizr
31
+ config.include_modernizr
32
+ end
33
+
34
+ def replace_canonical_subdomain?
35
+ config.replace_canonical_subdomain
32
36
  end
33
37
 
34
38
  def configure
35
- yield(category_collection)
39
+ yield(config)
36
40
  end
37
41
 
38
42
  end
@@ -1,8 +1,8 @@
1
1
  module Ress
2
2
 
3
- class CategoryCollection
3
+ class Config
4
4
 
5
- attr_accessor :include_modernizr
5
+ attr_accessor :include_modernizr, :replace_canonical_subdomain
6
6
  attr_reader :canonical_version, :alternate_versions
7
7
 
8
8
  def initialize
data/lib/ress/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ress
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -5,6 +5,7 @@ module Ress
5
5
  def ress_annotation_tags
6
6
  path = "#{request.host_with_port}#{request.fullpath}"
7
7
  html = if canonical_request?
8
+ path.gsub!("#{request.subdomain}.", '') if Ress.replace_canonical_subdomain?
8
9
  Ress.alternate_versions.map do |category|
9
10
  category.link_tag(request.protocol, path, self)
10
11
  end.join
@@ -1,8 +1,8 @@
1
1
  require_relative '../../lib/ress'
2
2
 
3
- describe Ress::CategoryCollection do
3
+ describe Ress::Config do
4
4
 
5
- let(:collection) { Ress::CategoryCollection.new }
5
+ let(:collection) { Ress::Config.new }
6
6
 
7
7
  describe '#add_alternate' do
8
8
 
@@ -69,6 +69,11 @@ describe Ress::Subdomain do
69
69
  'http://foo.bar.com/some/stuff'
70
70
  end
71
71
 
72
+ it 'replaces alternate subdomains with the cannonical subdomain' do
73
+ subdomain.url('http://', 'm.bar.com/some/stuff', 'm').should ==
74
+ 'http://foo.bar.com/some/stuff'
75
+ end
76
+
72
77
  end
73
78
  end
74
79
 
@@ -37,18 +37,27 @@ describe ActionView::Base do
37
37
  let(:request) { stub('request', :protocol => 'http://', :host_with_port => 'foo.com', :fullpath => '/bar', :subdomain => '') }
38
38
  before { view.stub(:canonical_request? => true) }
39
39
 
40
- it 'returns an empty string if there are no registered categories' do
41
- view.ress_annotation_tags.should == ''
40
+ context 'with no alternate versions' do
41
+ it 'returns an empty string' do
42
+ view.ress_annotation_tags.should == ''
43
+ end
42
44
  end
43
45
 
44
- it 'generates the link tags when there is one category' do
46
+ context 'with one alternate version' do
47
+ before(:all) { Ress.configure { |r| r.add_alternate :name => 'm', :media => 'stuff' } }
45
48
 
46
- Ress.configure do |r|
47
- r.add_alternate :name => 'm', :media => 'stuff'
49
+ it 'generates the link tags when there is one category' do
50
+ view.ress_annotation_tags.should ==
51
+ "<link href=\"http://m.foo.com/bar\" id=\"m\" media=\"stuff\" rel=\"alternate\" />"
48
52
  end
49
53
 
50
- view.ress_annotation_tags.should ==
54
+ it 'replaces the canonical subdomain when configured' do
55
+ request.stub(:host_with_port => 'www.foo.com', :subdomain => 'www')
56
+ Ress.stub(:replace_canonical_subdomain? => true )
57
+ view.ress_annotation_tags.should ==
51
58
  "<link href=\"http://m.foo.com/bar\" id=\"m\" media=\"stuff\" rel=\"alternate\" />"
59
+ end
60
+
52
61
  end
53
62
 
54
63
  end
data/spec/ress_spec.rb CHANGED
@@ -5,7 +5,7 @@ describe Ress do
5
5
  describe '.configure' do
6
6
 
7
7
  it 'yields the default category collection' do
8
- Ress.configure { |r| r.should be_a(Ress::CategoryCollection) }
8
+ Ress.configure { |r| r.should be_a(Ress::Config) }
9
9
  end
10
10
 
11
11
  end
@@ -51,4 +51,20 @@ describe Ress do
51
51
 
52
52
  end
53
53
 
54
+ describe '.replace_canonical_subdomain?' do
55
+
56
+ it 'defaults to false' do
57
+ Ress.replace_canonical_subdomain?.should be_false
58
+ end
59
+
60
+ it 'can be altered through Ress.configure' do
61
+ Ress.configure { |r| r.replace_canonical_subdomain = true }
62
+ Ress.replace_canonical_subdomain?.should be_true
63
+
64
+ Ress.configure { |r| r.replace_canonical_subdomain = false }
65
+ Ress.replace_canonical_subdomain?.should be_false
66
+ end
67
+
68
+ end
69
+
54
70
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ress
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.0.10
4
5
  prerelease:
5
- version: 0.0.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthew Robertson
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-05 00:00:00.000000000 Z
12
+ date: 2013-02-26 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
@@ -62,7 +62,7 @@ files:
62
62
  - lib/ress.rb
63
63
  - lib/ress/alternate_version.rb
64
64
  - lib/ress/canonical_version.rb
65
- - lib/ress/category_collection.rb
65
+ - lib/ress/config.rb
66
66
  - lib/ress/controller_additions.rb
67
67
  - lib/ress/engine.rb
68
68
  - lib/ress/subdomain.rb
@@ -71,7 +71,7 @@ files:
71
71
  - ress.gemspec
72
72
  - spec/ress/alternate_version_spec.rb
73
73
  - spec/ress/canonical_version_spec.rb
74
- - spec/ress/category_collection_spec.rb
74
+ - spec/ress/config_spec.rb
75
75
  - spec/ress/controller_additions_spec.rb
76
76
  - spec/ress/subdomain_spec.rb
77
77
  - spec/ress/view_helpers_spec.rb
@@ -105,7 +105,7 @@ summary: Progressively enhance the mobile user experience of your Rails applicat
105
105
  test_files:
106
106
  - spec/ress/alternate_version_spec.rb
107
107
  - spec/ress/canonical_version_spec.rb
108
- - spec/ress/category_collection_spec.rb
108
+ - spec/ress/config_spec.rb
109
109
  - spec/ress/controller_additions_spec.rb
110
110
  - spec/ress/subdomain_spec.rb
111
111
  - spec/ress/view_helpers_spec.rb