canonical-rails 0.2.5 → 0.2.11
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.
- checksums.yaml +4 -4
- data/app/helpers/canonical_rails/tag_helper.rb +20 -13
- data/lib/canonical-rails.rb +12 -2
- data/lib/canonical-rails/deprecation.rb +7 -0
- data/lib/canonical-rails/engine.rb +4 -2
- data/lib/canonical-rails/version.rb +1 -1
- data/lib/generators/canonical_rails/install/templates/canonical_rails.rb +2 -2
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a81685e6294e15e30d48ca8ce1bc15fcba1da4d58ccf16abe967b973e923310f
|
4
|
+
data.tar.gz: a9a783ecf48e8bd9824be40f5ac229cb121681aa30ed2859d48e34f47adbb534
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a91cb09a01bac779d159729212b21f12ff1349e2416a7defd810e53304f3be666cdb89bbaf1b95813b7ef29c01d080aa5a09647d751a8d08a617ea3e05c23bef
|
7
|
+
data.tar.gz: 0ea17f484eb95061b76f6845e56c81a240132512ddd719d11b2735bf80892f556525782acf09f2d8346c7886213f3176d7399833e437adf667e042abd6e29518
|
@@ -4,6 +4,15 @@ module CanonicalRails
|
|
4
4
|
request.params.key?('action') && CanonicalRails.sym_collection_actions.include?(request.params['action'].to_sym)
|
5
5
|
end
|
6
6
|
|
7
|
+
# Leave force_trailing_slash as nil to get the original behavior of trailing_slash_if_needed
|
8
|
+
def trailing_slash_config(force_trailing_slash = nil)
|
9
|
+
if force_trailing_slash
|
10
|
+
"/"
|
11
|
+
elsif force_trailing_slash.nil?
|
12
|
+
trailing_slash_if_needed
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
7
16
|
def trailing_slash_if_needed
|
8
17
|
"/" if trailing_slash_needed?
|
9
18
|
end
|
@@ -26,18 +35,18 @@ module CanonicalRails
|
|
26
35
|
(CanonicalRails.port || request.port).to_i
|
27
36
|
end
|
28
37
|
|
29
|
-
def canonical_href(host = canonical_host, port = canonical_port)
|
38
|
+
def canonical_href(host = canonical_host, port = canonical_port, force_trailing_slash = nil)
|
30
39
|
default_ports = { 'https://' => 443, 'http://' => 80 }
|
31
40
|
port = port.present? && port.to_i != default_ports[canonical_protocol] ? ":#{port}" : ''
|
32
|
-
raw "#{canonical_protocol}#{host}#{port}#{path_without_html_extension}#{
|
41
|
+
raw "#{canonical_protocol}#{host}#{port}#{path_without_html_extension}#{trailing_slash_config(force_trailing_slash)}#{allowed_query_string}"
|
33
42
|
end
|
34
43
|
|
35
|
-
def canonical_path
|
36
|
-
raw "#{path_without_html_extension}#{
|
44
|
+
def canonical_path(force_trailing_slash = nil)
|
45
|
+
raw "#{path_without_html_extension}#{trailing_slash_config(force_trailing_slash)}#{allowed_query_string}"
|
37
46
|
end
|
38
47
|
|
39
|
-
def canonical_tag(host = canonical_host, port = canonical_port)
|
40
|
-
canonical_url = canonical_href(host, port)
|
48
|
+
def canonical_tag(host = canonical_host, port = canonical_port, force_trailing_slash = nil)
|
49
|
+
canonical_url = canonical_href(host, port, force_trailing_slash)
|
41
50
|
capture do
|
42
51
|
if CanonicalRails.opengraph_url
|
43
52
|
concat tag(:meta, property: 'og:url', content: canonical_url)
|
@@ -46,15 +55,15 @@ module CanonicalRails
|
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
49
|
-
def
|
58
|
+
def allowed_params
|
50
59
|
selected_params = params.select do |key, value|
|
51
|
-
value.present? && CanonicalRails.
|
60
|
+
value.present? && CanonicalRails.sym_allowed_parameters.include?(key.to_sym)
|
52
61
|
end
|
53
62
|
|
54
63
|
selected_params.respond_to?(:to_unsafe_h) ? selected_params.to_unsafe_h : selected_params.to_h
|
55
64
|
end
|
56
65
|
|
57
|
-
def
|
66
|
+
def allowed_query_string
|
58
67
|
# Rack 1.4.5 fails to handle params that are not strings
|
59
68
|
# So if
|
60
69
|
# my_hash = { "a" => 1, "b" => 2}
|
@@ -64,10 +73,8 @@ module CanonicalRails
|
|
64
73
|
# https://github.com/rack/rack/blob/9939d40a5e23dcb058751d1029b794aa2f551900/test/spec_utils.rb#L222
|
65
74
|
# Rack 1.6.0 has it
|
66
75
|
# https://github.com/rack/rack/blob/65a7104b6b3e9ecd8f33c63a478ab9a33a103507/test/spec_utils.rb#L251
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
"?" + Rack::Utils.build_nested_query(convert_numeric_params(wl_params)) if wl_params.present?
|
76
|
+
parameters = allowed_params
|
77
|
+
"?" + Rack::Utils.build_nested_query(convert_numeric_params(parameters)) if parameters.present?
|
71
78
|
end
|
72
79
|
|
73
80
|
private
|
data/lib/canonical-rails.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "canonical-rails/engine"
|
2
|
+
require "canonical-rails/deprecation"
|
2
3
|
|
3
4
|
module CanonicalRails
|
4
5
|
|
@@ -23,9 +24,13 @@ module CanonicalRails
|
|
23
24
|
mattr_accessor :collection_actions
|
24
25
|
@@collection_actions = [:index]
|
25
26
|
|
27
|
+
# @deprecated: use config.allowed_parameters instead
|
26
28
|
mattr_accessor :whitelisted_parameters
|
27
29
|
@@whitelisted_parameters = []
|
28
30
|
|
31
|
+
mattr_accessor :allowed_parameters
|
32
|
+
@@allowed_parameters = []
|
33
|
+
|
29
34
|
mattr_accessor :opengraph_url
|
30
35
|
@@opengraph_url = false
|
31
36
|
|
@@ -33,7 +38,12 @@ module CanonicalRails
|
|
33
38
|
@@sym_collection_actions ||= self.collection_actions.map(&:to_sym)
|
34
39
|
end
|
35
40
|
|
36
|
-
def self.
|
37
|
-
@@
|
41
|
+
def self.sym_allowed_parameters
|
42
|
+
@@sym_allowed_parameters ||= if self.whitelisted_parameters.empty?
|
43
|
+
self.allowed_parameters.map(&:to_sym)
|
44
|
+
else
|
45
|
+
CanonicalRails::Deprecation.warn('config.whitelisted_parameters is deprecated, please use config.allowed_parameters instead.')
|
46
|
+
self.whitelisted_parameters.map(&:to_sym)
|
47
|
+
end
|
38
48
|
end
|
39
49
|
end
|
@@ -1,9 +1,11 @@
|
|
1
|
+
require_relative '../../app/helpers/canonical_rails/tag_helper'
|
2
|
+
|
1
3
|
module CanonicalRails
|
2
4
|
class Engine < ::Rails::Engine
|
3
|
-
|
5
|
+
|
4
6
|
initializer 'canonical_rails.add_helpers' do |app|
|
5
7
|
ActionView::Base.send :include, CanonicalRails::TagHelper
|
6
8
|
end
|
7
|
-
|
9
|
+
|
8
10
|
end
|
9
11
|
end
|
@@ -20,9 +20,9 @@ CanonicalRails.setup do |config|
|
|
20
20
|
config.collection_actions# = [:index]
|
21
21
|
|
22
22
|
# Parameter spamming can cause index dilution by creating seemingly different URLs with identical or near-identical content.
|
23
|
-
# Unless
|
23
|
+
# Unless allowed, these parameters will be omitted
|
24
24
|
|
25
|
-
config.
|
25
|
+
config.allowed_parameters# = []
|
26
26
|
|
27
27
|
# Output a matching OpenGraph URL meta tag (og:url) with the canonical URL, as recommended by Facebook et al
|
28
28
|
config.opengraph_url#= true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canonical-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Ivanov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
version: '4.1'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '6.
|
22
|
+
version: '6.2'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -29,7 +29,7 @@ dependencies:
|
|
29
29
|
version: '4.1'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '6.
|
32
|
+
version: '6.2'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: appraisal
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,19 +45,19 @@ dependencies:
|
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
48
|
+
name: sprockets
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- - "
|
51
|
+
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
53
|
+
version: '3.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- - "
|
58
|
+
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
60
|
+
version: '3.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rspec-rails
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- app/helpers/canonical_rails/tag_helper.rb
|
102
102
|
- config/routes.rb
|
103
103
|
- lib/canonical-rails.rb
|
104
|
+
- lib/canonical-rails/deprecation.rb
|
104
105
|
- lib/canonical-rails/engine.rb
|
105
106
|
- lib/canonical-rails/version.rb
|
106
107
|
- lib/generators/canonical_rails/install/install_generator.rb
|
@@ -109,7 +110,7 @@ files:
|
|
109
110
|
homepage: https://github.com/jumph4x/canonical-rails
|
110
111
|
licenses: []
|
111
112
|
metadata: {}
|
112
|
-
post_install_message:
|
113
|
+
post_install_message:
|
113
114
|
rdoc_options: []
|
114
115
|
require_paths:
|
115
116
|
- lib
|
@@ -124,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
125
|
- !ruby/object:Gem::Version
|
125
126
|
version: '0'
|
126
127
|
requirements: []
|
127
|
-
|
128
|
-
|
129
|
-
signing_key:
|
128
|
+
rubygems_version: 3.0.6
|
129
|
+
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Simple and configurable Rails canonical ref tag helper
|
132
132
|
test_files: []
|