zhulei-canonical-rails 0.2.4 → 1.0.0

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
2
  SHA1:
3
- metadata.gz: acc681c37ea0f9af61bec19afb7deda532ea20c4
4
- data.tar.gz: de43c2f57a89718d3700a810c6a1b6bd7110121c
3
+ metadata.gz: d8fa34924f6d0b05caad59dfddb9a5e92b3fc112
4
+ data.tar.gz: ac6632b6ede8ae189931afdfba57f158c79445eb
5
5
  SHA512:
6
- metadata.gz: e684c3090e13c3240032fe2b6bc3c278f6a2fe781a1339b29fc1cb082ff1fb127543e2fbb4fae6e6f6c7113385e8414c3671cc5d1b46135593549043f5bd2ca4
7
- data.tar.gz: 8711add62a7b3bdfe6e0bd1580b368bd21ab425718b582cc90b67497a31c3e9b32af82a95acc55ac74791bc58e9972160ed30b1add62f7f4d3225dce01a14a3e
6
+ metadata.gz: b0b21472b360672d223af326bce3b810bd0a17de5a2ca82ada770b5704cb50f1468387e3a10bf9d5ec5308697adc85b14086990d7337e850fb020ed092470f61
7
+ data.tar.gz: be9530a917c98de4f8126f83cf76d0d2a3a7ca3fdac908e794065f7ed6c3827ab65fdf1568c7ac0c1de665211d496784f5c68b3bf00708dccc3edef0b5337f95
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- CanonicalRails
1
+ ZhuleiCanonicalRails
2
2
  ==============
3
3
  [![Build Status](https://travis-ci.org/jumph4x/canonical-rails.svg?branch=master)](https://travis-ci.org/jumph4x/canonical-rails)
4
4
 
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ end
14
14
 
15
15
  RDoc::Task.new(:rdoc) do |rdoc|
16
16
  rdoc.rdoc_dir = 'rdoc'
17
- rdoc.title = 'CanonicalRails'
17
+ rdoc.title = 'ZhuleiCanonicalRails'
18
18
  rdoc.options << '--line-numbers'
19
19
  rdoc.rdoc_files.include('README.rdoc')
20
20
  rdoc.rdoc_files.include('lib/**/*.rb')
@@ -1,77 +1,77 @@
1
- module CanonicalRails
2
- module TagHelper
3
- def trailing_slash_needed?
4
- request.params.key?('action') && CanonicalRails.sym_collection_actions.include?(request.params['action'].to_sym)
5
- end
6
-
7
- def trailing_slash_if_needed
8
- "/" if trailing_slash_needed? && request.path != '/'
9
- end
10
-
11
- def path_without_html_extension
12
- request.path.sub(/\.html$/, '')
13
- end
14
-
15
- def canonical_protocol
16
- CanonicalRails.protocol || request.protocol
17
- end
18
-
19
- def canonical_host
20
- CanonicalRails.host || request.host
21
- end
22
-
23
- def canonical_port
24
- (CanonicalRails.port || request.port).to_i
25
- end
26
-
27
- def canonical_href(host = canonical_host, port = canonical_port)
28
- default_ports = { 'https://' => 443, 'http://' => 80 }
29
- port = port.present? && port.to_i != default_ports[canonical_protocol] ? ":#{port}" : ''
30
- raw "#{canonical_protocol}#{host}#{path_without_html_extension}#{whitelisted_query_string}"
31
- end
32
-
33
- def canonical_path
34
- raw "#{path_without_html_extension}#{trailing_slash_if_needed}#{whitelisted_query_string}"
35
- end
36
-
37
- def canonical_tag(host = canonical_host, port = canonical_port)
38
- canonical_url = canonical_href(host, port)
39
- capture do
40
- if CanonicalRails.opengraph_url
41
- concat tag(:meta, property: 'og:url', content: canonical_url)
42
- end
43
- concat tag(:link, href: canonical_url, rel: :canonical)
44
- end
45
- end
46
-
47
- def whitelisted_params
48
- selected_params = params.select do |key, value|
49
- value.present? && CanonicalRails.sym_whitelisted_parameters.include?(key.to_sym)
50
- end
51
-
52
- selected_params.respond_to?(:to_unsafe_h) ? selected_params.to_unsafe_h : selected_params.to_h
53
- end
54
-
55
- def whitelisted_query_string
56
- # Rack 1.4.5 fails to handle params that are not strings
57
- # So if
58
- # my_hash = { "a" => 1, "b" => 2}
59
- # Rack::Utils.build_nested_query(my_hash) would return
60
- # "a&b"
61
- # Rack 1.4.5 did not have a test case for this scenario
62
- # https://github.com/rack/rack/blob/9939d40a5e23dcb058751d1029b794aa2f551900/test/spec_utils.rb#L222
63
- # Rack 1.6.0 has it
64
- # https://github.com/rack/rack/blob/65a7104b6b3e9ecd8f33c63a478ab9a33a103507/test/spec_utils.rb#L251
65
-
66
- wl_params = whitelisted_params
67
-
68
- "?" + Rack::Utils.build_nested_query(convert_numeric_params(wl_params)) if wl_params.present?
69
- end
70
-
71
- private
72
-
73
- def convert_numeric_params(params_hash)
74
- Hash[params_hash.map { |k, v| v.is_a?(Numeric) ? [k, v.to_s] : [k, v] }]
75
- end
76
- end
77
- end
1
+ module ZhuleiCanonicalRails
2
+ module TagHelper
3
+ def trailing_slash_needed?
4
+ request.params.key?('action') && ZhuleiCanonicalRails.sym_collection_actions.include?(request.params['action'].to_sym)
5
+ end
6
+
7
+ def trailing_slash_if_needed
8
+ "/" if trailing_slash_needed? && request.path != '/'
9
+ end
10
+
11
+ def path_without_html_extension
12
+ request.path.sub(/\.html$/, '')
13
+ end
14
+
15
+ def canonical_protocol
16
+ ZhuleiCanonicalRails.protocol || request.protocol
17
+ end
18
+
19
+ def canonical_host
20
+ ZhuleiCanonicalRails.host || request.host
21
+ end
22
+
23
+ def canonical_port
24
+ (ZhuleiCanonicalRails.port || request.port).to_i
25
+ end
26
+
27
+ def canonical_href(host = canonical_host, port = canonical_port)
28
+ default_ports = { 'https://' => 443, 'http://' => 80 }
29
+ port = port.present? && port.to_i != default_ports[canonical_protocol] ? ":#{port}" : ''
30
+ raw "#{canonical_protocol}#{host}#{path_without_html_extension}#{whitelisted_query_string}"
31
+ end
32
+
33
+ def canonical_path
34
+ raw "#{path_without_html_extension}#{trailing_slash_if_needed}#{whitelisted_query_string}"
35
+ end
36
+
37
+ def canonical_tag(host = canonical_host, port = canonical_port)
38
+ canonical_url = canonical_href(host, port)
39
+ capture do
40
+ if ZhuleiCanonicalRails.opengraph_url
41
+ concat tag(:meta, property: 'og:url', content: canonical_url)
42
+ end
43
+ concat tag(:link, href: canonical_url, rel: :canonical)
44
+ end
45
+ end
46
+
47
+ def whitelisted_params
48
+ selected_params = params.select do |key, value|
49
+ value.present? && ZhuleiCanonicalRails.sym_whitelisted_parameters.include?(key.to_sym)
50
+ end
51
+
52
+ selected_params.respond_to?(:to_unsafe_h) ? selected_params.to_unsafe_h : selected_params.to_h
53
+ end
54
+
55
+ def whitelisted_query_string
56
+ # Rack 1.4.5 fails to handle params that are not strings
57
+ # So if
58
+ # my_hash = { "a" => 1, "b" => 2}
59
+ # Rack::Utils.build_nested_query(my_hash) would return
60
+ # "a&b"
61
+ # Rack 1.4.5 did not have a test case for this scenario
62
+ # https://github.com/rack/rack/blob/9939d40a5e23dcb058751d1029b794aa2f551900/test/spec_utils.rb#L222
63
+ # Rack 1.6.0 has it
64
+ # https://github.com/rack/rack/blob/65a7104b6b3e9ecd8f33c63a478ab9a33a103507/test/spec_utils.rb#L251
65
+
66
+ wl_params = whitelisted_params
67
+
68
+ "?" + Rack::Utils.build_nested_query(convert_numeric_params(wl_params)) if wl_params.present?
69
+ end
70
+
71
+ private
72
+
73
+ def convert_numeric_params(params_hash)
74
+ Hash[params_hash.map { |k, v| v.is_a?(Numeric) ? [k, v.to_s] : [k, v] }]
75
+ end
76
+ end
77
+ end
@@ -1,8 +1,8 @@
1
- module CanonicalRails
1
+ module ZhuleiCanonicalRails
2
2
  class Engine < ::Rails::Engine
3
3
 
4
4
  initializer 'canonical_rails.add_helpers' do |app|
5
- ActionView::Base.send :include, CanonicalRails::TagHelper
5
+ ActionView::Base.send :include, ZhuleiCanonicalRails::TagHelper
6
6
  end
7
7
 
8
8
  end
@@ -1,3 +1,3 @@
1
- module CanonicalRails
2
- VERSION = "0.2.4"
1
+ module ZhuleiCanonicalRails
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require "canonical-rails/engine"
2
2
 
3
- module CanonicalRails
3
+ module ZhuleiCanonicalRails
4
4
 
5
- # Default way to setup CanonicalRails. Run `rails g canonical_rails:install` to create
5
+ # Default way to setup ZhuleiCanonicalRails. Run `rails g canonical_rails:install` to create
6
6
  # a fresh initializer with all configuration values.
7
7
  #
8
8
  # the config\setup concept politely observed at and borrowed from Devise: https://github.com/plataformatec/devise/blob/master/lib/devise.rb
@@ -1,4 +1,4 @@
1
- module CanonicalRails
1
+ module ZhuleiCanonicalRails
2
2
  class InstallGenerator < Rails::Generators::Base
3
3
 
4
4
  def self.source_paths
@@ -1,6 +1,6 @@
1
1
  # Do yourself a favor and set these up right when you install the engine.
2
2
 
3
- CanonicalRails.setup do |config|
3
+ ZhuleiCanonicalRails.setup do |config|
4
4
 
5
5
  # Force the protocol. If you do not specify, the protocol will be based on the incoming request's protocol.
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zhulei-canonical-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Denis Ivanov
7
+ - Zhu Lei
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-25 00:00:00.000000000 Z
11
+ date: 2018-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,11 +86,10 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
- description: 'Configurable, but assumes a conservative strategy by default with a
90
- goal to solve many search engine index problems: multiple hostnames, inbound links
91
- with arbitrary parameters, trailing slashes. '
89
+ description: This gem is based on canonical-rails by Denis Ivanov,I only delete the
90
+ port in the url and delete the lower-case method in the code.
92
91
  email:
93
- - visible@jumph4x.net
92
+ - zhuleichina@qq.com
94
93
  executables: []
95
94
  extensions: []
96
95
  extra_rdoc_files: []
@@ -125,8 +124,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
124
  version: '0'
126
125
  requirements: []
127
126
  rubyforge_project:
128
- rubygems_version: 2.5.2
127
+ rubygems_version: 2.6.14
129
128
  signing_key:
130
129
  specification_version: 4
131
- summary: Simple and configurable Rails canonical ref tag helper
130
+ summary: canonical-rails by Denis Ivanov,delete the port in the url and delete the
131
+ lower-case method in the code
132
132
  test_files: []