canonical-rails 0.2.1 → 0.2.15

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 493140cf6a89545c33141ea88e762de816853cdc
4
- data.tar.gz: 15ea886c64d6a83d6bf4149c88ce324fa95e1c8b
2
+ SHA256:
3
+ metadata.gz: cf9e6c0398f9b204f9cdcdf73d2ea3607fddc75fad061f8a6057b5c83c5b3fb8
4
+ data.tar.gz: 07d0d5b92eb285da22f61e13cec4203af2abac3453e5e8370bcd2eba0de03aa1
5
5
  SHA512:
6
- metadata.gz: 65dee720050ac6ed7574a3cd7ed40da9f32fa4f21af0b8953f8ab9d87bce86279289055ac5ba77b4d967b324ea13df4346b546e26676e55c7faacfa95718b743
7
- data.tar.gz: a85c78bc01e5b9f3f7d0099c61cfffa3a0f8d27fea49feea40c0ca631d3eedc2560adcb99125925b691cff7f274fba7e8b039f439961a32772ba148635835fed
6
+ metadata.gz: '018c55179322a1807e0b7bde285b38d0927345bcf74774a79efb829d05bac226c6743757f2c73b9ded0a9ee5230073850e74126a0e3a1ad55e3f9b7a9a6513bd'
7
+ data.tar.gz: 0620d371b5fc2cb139afed5550f3635f5ffecb735e0979681f3239676c54b57bd7f3197fdaa2ba12f51fcd484893a1ceb7f3fba620061c03f9afb04f34a86837
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  CanonicalRails
2
2
  ==============
3
- [![Dependency Status](https://gemnasium.com/jumph4x/canonical-rails.png)](https://gemnasium.com/jumph4x/canonical-rails)
4
3
  [![Build Status](https://travis-ci.org/jumph4x/canonical-rails.svg?branch=master)](https://travis-ci.org/jumph4x/canonical-rails)
5
4
 
6
5
  A number of articles exist explaining the issue concisely and at length:
@@ -37,5 +36,4 @@ your HTML views:
37
36
 
38
37
  ## Cred
39
38
 
40
- A project by [Downshift Labs](http://downshiftlabs.com), Ruby on Rails,
41
- Performance tuning and Spree Commerce projects.
39
+ Originally developed for [FCP Euro - High Quality European Car Parts](https://www.fcpeuro.com).
@@ -4,12 +4,23 @@ 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
- def path_without_html_extension
12
- request.path.sub(/\.html$/, '')
20
+ def path_without_extension
21
+ return '' if request.path == '/'
22
+
23
+ request.path.sub(/\.\w{3,4}$/, '')
13
24
  end
14
25
 
15
26
  def canonical_protocol
@@ -24,14 +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}"
41
+ raw "#{canonical_protocol}#{host}#{port}#{path_without_extension}#{trailing_slash_config(force_trailing_slash)}#{allowed_query_string}"
31
42
  end
32
43
 
33
- def canonical_tag(host = canonical_host, port = canonical_port)
34
- canonical_url = canonical_href(host, port)
44
+ def canonical_path(force_trailing_slash = nil)
45
+ raw "#{path_without_extension}#{trailing_slash_config(force_trailing_slash)}#{allowed_query_string}"
46
+ end
47
+
48
+ def canonical_tag(host = canonical_host, port = canonical_port, force_trailing_slash = nil)
49
+ canonical_url = canonical_href(host, port, force_trailing_slash)
35
50
  capture do
36
51
  if CanonicalRails.opengraph_url
37
52
  concat tag(:meta, property: 'og:url', content: canonical_url)
@@ -40,15 +55,15 @@ module CanonicalRails
40
55
  end
41
56
  end
42
57
 
43
- def whitelisted_params
58
+ def allowed_params
44
59
  selected_params = params.select do |key, value|
45
- value.present? && CanonicalRails.sym_whitelisted_parameters.include?(key.to_sym)
60
+ value.present? && CanonicalRails.sym_allowed_parameters.include?(key.to_sym)
46
61
  end
47
62
 
48
63
  selected_params.respond_to?(:to_unsafe_h) ? selected_params.to_unsafe_h : selected_params.to_h
49
64
  end
50
65
 
51
- def whitelisted_query_string
66
+ def allowed_query_string
52
67
  # Rack 1.4.5 fails to handle params that are not strings
53
68
  # So if
54
69
  # my_hash = { "a" => 1, "b" => 2}
@@ -58,10 +73,8 @@ module CanonicalRails
58
73
  # https://github.com/rack/rack/blob/9939d40a5e23dcb058751d1029b794aa2f551900/test/spec_utils.rb#L222
59
74
  # Rack 1.6.0 has it
60
75
  # https://github.com/rack/rack/blob/65a7104b6b3e9ecd8f33c63a478ab9a33a103507/test/spec_utils.rb#L251
61
-
62
- wl_params = whitelisted_params
63
-
64
- "?" + 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?
65
78
  end
66
79
 
67
80
  private
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/deprecation'
4
+
5
+ module CanonicalRails
6
+ Deprecation = ActiveSupport::Deprecation.new('1.0', 'CanonicalRails')
7
+ 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.1"
2
+ VERSION = "0.2.15"
3
3
  end
@@ -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.sym_whitelisted_parameters
37
- @@sym_whitelisted_parameters ||= self.whitelisted_parameters.map(&:to_sym)
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
@@ -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,25 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canonical-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2023-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: actionview
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
- - - "<"
20
+ - - "<="
21
21
  - !ruby/object:Gem::Version
22
- version: '5.2'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,25 +27,31 @@ dependencies:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '4.1'
30
- - - "<"
30
+ - - "<="
31
31
  - !ruby/object:Gem::Version
32
- version: '5.2'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
- name: appraisal
34
+ name: actionpack
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '4.1'
40
+ - - "<="
41
+ - !ruby/object:Gem::Version
42
+ version: '7.1'
40
43
  type: :development
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
43
46
  requirements:
44
47
  - - ">="
45
48
  - !ruby/object:Gem::Version
46
- version: '0'
49
+ version: '4.1'
50
+ - - "<="
51
+ - !ruby/object:Gem::Version
52
+ version: '7.1'
47
53
  - !ruby/object:Gem::Dependency
48
- name: sqlite3
54
+ name: appraisal
49
55
  requirement: !ruby/object:Gem::Requirement
50
56
  requirements:
51
57
  - - ">="
@@ -64,14 +70,14 @@ dependencies:
64
70
  requirements:
65
71
  - - "~>"
66
72
  - !ruby/object:Gem::Version
67
- version: '3.5'
73
+ version: 4.0.1
68
74
  type: :development
69
75
  prerelease: false
70
76
  version_requirements: !ruby/object:Gem::Requirement
71
77
  requirements:
72
78
  - - "~>"
73
79
  - !ruby/object:Gem::Version
74
- version: '3.5'
80
+ version: 4.0.1
75
81
  - !ruby/object:Gem::Dependency
76
82
  name: pry
77
83
  requirement: !ruby/object:Gem::Requirement
@@ -101,13 +107,15 @@ files:
101
107
  - app/helpers/canonical_rails/tag_helper.rb
102
108
  - config/routes.rb
103
109
  - lib/canonical-rails.rb
110
+ - lib/canonical-rails/deprecation.rb
104
111
  - lib/canonical-rails/engine.rb
105
112
  - lib/canonical-rails/version.rb
106
113
  - lib/generators/canonical_rails/install/install_generator.rb
107
114
  - lib/generators/canonical_rails/install/templates/canonical_rails.rb
108
115
  - lib/tasks/canonical-rails_tasks.rake
109
116
  homepage: https://github.com/jumph4x/canonical-rails
110
- licenses: []
117
+ licenses:
118
+ - MIT
111
119
  metadata: {}
112
120
  post_install_message:
113
121
  rdoc_options: []
@@ -124,8 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
132
  - !ruby/object:Gem::Version
125
133
  version: '0'
126
134
  requirements: []
127
- rubyforge_project:
128
- rubygems_version: 2.4.3
135
+ rubygems_version: 3.4.19
129
136
  signing_key:
130
137
  specification_version: 4
131
138
  summary: Simple and configurable Rails canonical ref tag helper