ress 0.0.4 → 0.0.5
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.
@@ -19,19 +19,17 @@ module Ress
|
|
19
19
|
# Create a tag of this format:
|
20
20
|
# `<link rel="canonical" href="http://www.example.com/page-1" >`
|
21
21
|
def link_tag(protocol, fullpath, subdomain, view)
|
22
|
-
view.tag :link, :rel => 'canonical', :href =>
|
22
|
+
view.tag :link, :rel => 'canonical', :href => url(protocol, fullpath, subdomain)
|
23
23
|
end
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
"#{protocol}#{fullpath}"
|
33
|
-
end
|
25
|
+
def url(protocol, fullpath, subdomain)
|
26
|
+
fullpath = fullpath[(subdomain.length + 1)..-1] unless subdomain.empty?
|
27
|
+
if self.subdomain
|
28
|
+
"#{protocol}#{self.subdomain}.#{fullpath}"
|
29
|
+
else
|
30
|
+
"#{protocol}#{fullpath}"
|
34
31
|
end
|
32
|
+
end
|
35
33
|
|
36
34
|
end
|
37
35
|
|
@@ -5,10 +5,18 @@ module Ress
|
|
5
5
|
|
6
6
|
def self.included(base)
|
7
7
|
base.helper_method :canonical_request?
|
8
|
-
base.
|
8
|
+
base.helper_method :force_canonical_url
|
9
|
+
base.before_filter :set_force_canonical_cookie
|
10
|
+
base.before_filter :prepend_alternate_view_path
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
13
|
+
def set_force_canonical_cookie
|
14
|
+
if params[:force_canonical]
|
15
|
+
cookies[:force_canonical] = 1
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def prepend_alternate_view_path
|
12
20
|
Ress.alternate_versions.each do |cat|
|
13
21
|
prepend_view_path(cat.view_path) if cat.matches?(request.subdomain)
|
14
22
|
end
|
@@ -18,6 +26,14 @@ module Ress
|
|
18
26
|
Ress.canonical_version.matches?(request.subdomain)
|
19
27
|
end
|
20
28
|
|
29
|
+
def force_canonical_url
|
30
|
+
path = "#{request.host_with_port}#{request.fullpath}"
|
31
|
+
url = Ress.canonical_version.url(request.protocol, path, request.subdomain)
|
32
|
+
sep = url.include?('?') ? '&' : '?'
|
33
|
+
|
34
|
+
"#{url}#{sep}force_canonical=1"
|
35
|
+
end
|
36
|
+
|
21
37
|
end
|
22
38
|
end
|
23
39
|
|
data/lib/ress/version.rb
CHANGED
@@ -23,10 +23,10 @@ end
|
|
23
23
|
describe Ress::ControllerAdditions do
|
24
24
|
|
25
25
|
it 'adds a before_filter to all actions when it is included' do
|
26
|
-
ActionControllerStub.action.should == :
|
26
|
+
ActionControllerStub.action.should == :prepend_alternate_view_path
|
27
27
|
end
|
28
28
|
|
29
|
-
describe '#
|
29
|
+
describe '#prepend_alternate_view_path' do
|
30
30
|
|
31
31
|
let(:controller) { ActionControllerStub.new }
|
32
32
|
|
@@ -40,7 +40,7 @@ describe Ress::ControllerAdditions do
|
|
40
40
|
Ress.stub(:alternate_versions => [category])
|
41
41
|
|
42
42
|
controller.should_receive(:prepend_view_path).with('foo/bar')
|
43
|
-
controller.
|
43
|
+
controller.prepend_alternate_view_path
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'does not prepend view paths of alternate_versions that dont match' do
|
@@ -48,7 +48,7 @@ describe Ress::ControllerAdditions do
|
|
48
48
|
Ress.stub(:alternate_versions => [category])
|
49
49
|
|
50
50
|
controller.should_not_receive(:prepend_view_path)
|
51
|
-
controller.
|
51
|
+
controller.prepend_alternate_view_path
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -69,4 +69,29 @@ describe Ress::ControllerAdditions do
|
|
69
69
|
|
70
70
|
end
|
71
71
|
|
72
|
+
describe '#force_canonical_url' do
|
73
|
+
|
74
|
+
let(:controller) { ActionControllerStub.new }
|
75
|
+
|
76
|
+
before do
|
77
|
+
@request = stub({
|
78
|
+
:subdomain => 'foo',
|
79
|
+
:host_with_port => 'foo.bar.com',
|
80
|
+
:protocol => 'http://'
|
81
|
+
})
|
82
|
+
controller.stub(:request => @request)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'appends params to the current url properly if there are no GET params' do
|
86
|
+
@request.stub(:fullpath => '/some_place')
|
87
|
+
controller.force_canonical_url.should == 'http://bar.com/some_place?force_canonical=1'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'appends params to the current url properly when there are GET params' do
|
91
|
+
@request.stub(:fullpath => '/some_place?param=something')
|
92
|
+
controller.force_canonical_url.should == 'http://bar.com/some_place?param=something&force_canonical=1'
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
72
97
|
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
|
5
4
|
prerelease:
|
5
|
+
version: 0.0.5
|
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
|
-
|
16
|
-
prerelease: false
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
15
|
+
version_requirements: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '3.0'
|
22
20
|
none: false
|
21
|
+
name: actionpack
|
23
22
|
type: :runtime
|
24
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: !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
|
-
|
32
|
-
prerelease: false
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
34
32
|
requirements:
|
35
33
|
- - ! '>='
|
36
34
|
- !ruby/object:Gem::Version
|
37
35
|
version: '0'
|
38
36
|
none: false
|
37
|
+
name: rspec
|
39
38
|
type: :development
|
40
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
43
43
|
- !ruby/object:Gem::Version
|