canonical-rails 0.2.4 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0d9ef773da11596654f1a0c5417e77410bcbac6594dc1adccb544edef085d66
4
- data.tar.gz: f900d781c65c89cab82b65885ab0b07bcc7bab959929d2b91508ed5295579c4e
3
+ metadata.gz: 7cc8c724bb2b64e543b2becad527e27a2828bd4113032ecb396f5c8f6425f0e2
4
+ data.tar.gz: df6126c3991db70dfea28424bf78b64a8a216e1634e3d8f33f1e9c624e33218a
5
5
  SHA512:
6
- metadata.gz: 78ab25beac66412f2437f19aa34309e0374a1d115ccfffb7b0d1dffb42cc9a9a73f5cc7f3d44a35ae1ce62ca989197bafec3f1f11590a7ef7dd0b27b46141b7a
7
- data.tar.gz: d360b87780f9e2c663a18a553961b658f3defade38f7c4724c6b1c838bec7e9d9c91680030eae8016cd87145814d8a495a2cdda60b85cb3f1f521b89a8b48a1d
6
+ metadata.gz: dafcabbeea6d18de1a8e50d7402e4169d0e451d8fa47a4bb4b311c7e9f616aa78314725ef2ef6684fe44c7a424525d92f58bbd6f9a99540805ecacc0416ab4da
7
+ data.tar.gz: 3ddf2e2e9fd2423c7eb6f2675755d7ea0461233aa13a61289274129124e1e32cc1b6e9470d74911902baeb5ca165493f8125d5fa1f875186d242c46ee4115b65
@@ -4,11 +4,22 @@ 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
- "/" if trailing_slash_needed? && request.path != '/'
17
+ "/" if trailing_slash_needed?
9
18
  end
10
19
 
11
20
  def path_without_html_extension
21
+ return '' if request.path == '/'
22
+
12
23
  request.path.sub(/\.html$/, '')
13
24
  end
14
25
 
@@ -24,18 +35,18 @@ module CanonicalRails
24
35
  (CanonicalRails.port || request.port).to_i
25
36
  end
26
37
 
27
- def canonical_href(host = canonical_host, port = canonical_port)
38
+ def canonical_href(host = canonical_host, port = canonical_port, force_trailing_slash = nil)
28
39
  default_ports = { 'https://' => 443, 'http://' => 80 }
29
40
  port = port.present? && port.to_i != default_ports[canonical_protocol] ? ":#{port}" : ''
30
- raw "#{canonical_protocol}#{host}#{port}#{path_without_html_extension}#{trailing_slash_if_needed}#{whitelisted_query_string}".downcase
41
+ raw "#{canonical_protocol}#{host}#{port}#{path_without_html_extension}#{trailing_slash_config(force_trailing_slash)}#{allowed_query_string}"
31
42
  end
32
-
33
- def canonical_path
34
- raw "#{path_without_html_extension}#{trailing_slash_if_needed}#{whitelisted_query_string}"
43
+
44
+ def canonical_path(force_trailing_slash = nil)
45
+ raw "#{path_without_html_extension}#{trailing_slash_config(force_trailing_slash)}#{allowed_query_string}"
35
46
  end
36
47
 
37
- def canonical_tag(host = canonical_host, port = canonical_port)
38
- 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)
39
50
  capture do
40
51
  if CanonicalRails.opengraph_url
41
52
  concat tag(:meta, property: 'og:url', content: canonical_url)
@@ -44,15 +55,15 @@ module CanonicalRails
44
55
  end
45
56
  end
46
57
 
47
- def whitelisted_params
58
+ def allowed_params
48
59
  selected_params = params.select do |key, value|
49
- value.present? && CanonicalRails.sym_whitelisted_parameters.include?(key.to_sym)
60
+ value.present? && CanonicalRails.sym_allowed_parameters.include?(key.to_sym)
50
61
  end
51
62
 
52
63
  selected_params.respond_to?(:to_unsafe_h) ? selected_params.to_unsafe_h : selected_params.to_h
53
64
  end
54
65
 
55
- def whitelisted_query_string
66
+ def allowed_query_string
56
67
  # Rack 1.4.5 fails to handle params that are not strings
57
68
  # So if
58
69
  # my_hash = { "a" => 1, "b" => 2}
@@ -63,7 +74,7 @@ module CanonicalRails
63
74
  # Rack 1.6.0 has it
64
75
  # https://github.com/rack/rack/blob/65a7104b6b3e9ecd8f33c63a478ab9a33a103507/test/spec_utils.rb#L251
65
76
 
66
- wl_params = whitelisted_params
77
+ wl_params = allowed_params
67
78
 
68
79
  "?" + Rack::Utils.build_nested_query(convert_numeric_params(wl_params)) if wl_params.present?
69
80
  end
@@ -23,8 +23,8 @@ module CanonicalRails
23
23
  mattr_accessor :collection_actions
24
24
  @@collection_actions = [:index]
25
25
 
26
- mattr_accessor :whitelisted_parameters
27
- @@whitelisted_parameters = []
26
+ mattr_accessor :allowed_parameters
27
+ @@allowed_parameters = []
28
28
 
29
29
  mattr_accessor :opengraph_url
30
30
  @@opengraph_url = false
@@ -33,7 +33,7 @@ module CanonicalRails
33
33
  @@sym_collection_actions ||= self.collection_actions.map(&:to_sym)
34
34
  end
35
35
 
36
- def self.sym_whitelisted_parameters
37
- @@sym_whitelisted_parameters ||= self.whitelisted_parameters.map(&:to_sym)
36
+ def self.sym_allowed_parameters
37
+ @@sym_allowed_parameters ||= self.allowed_parameters.map(&:to_sym)
38
38
  end
39
39
  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
@@ -1,3 +1,3 @@
1
1
  module CanonicalRails
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.10"
3
3
  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 whitelisted, these parameters will be omitted
23
+ # Unless allowed, these parameters will be omitted
24
24
 
25
- config.whitelisted_parameters# = []
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
4
+ version: 0.2.10
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: 2018-08-07 00:00:00.000000000 Z
11
+ date: 2020-12-11 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: '5.3'
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: '5.3'
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: sqlite3
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
@@ -109,7 +109,7 @@ files:
109
109
  homepage: https://github.com/jumph4x/canonical-rails
110
110
  licenses: []
111
111
  metadata: {}
112
- post_install_message:
112
+ post_install_message:
113
113
  rdoc_options: []
114
114
  require_paths:
115
115
  - lib
@@ -124,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.7.7
129
- signing_key:
127
+ rubygems_version: 3.0.6
128
+ signing_key:
130
129
  specification_version: 4
131
130
  summary: Simple and configurable Rails canonical ref tag helper
132
131
  test_files: []