zhulei-canonical-rails 0.1.1 → 0.2.4

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: 0ea38f0bd5a67f2ca610c99b990452e8da1a8bad
4
- data.tar.gz: 56bb0136aa7d06c1c572b26baa6da834d5206bdc
3
+ metadata.gz: acc681c37ea0f9af61bec19afb7deda532ea20c4
4
+ data.tar.gz: de43c2f57a89718d3700a810c6a1b6bd7110121c
5
5
  SHA512:
6
- metadata.gz: 72e1da0fdb9f99484681049da83ae17b91fbd21e3b280b36d3c9fb7bcea2bdb7a944f622c4c9f5f963913872e4bfbb34e62f9f7fb1fc303572ebc7c0f81151af
7
- data.tar.gz: 701cc5f2859f2756d50e72a125b43dbfb1b016c40b10738b7a69790b680fa833c5f15ff7921413b05c339cc5bb8ed3ef4ffbcc5420942862f367d3b2da05fa4d
6
+ metadata.gz: e684c3090e13c3240032fe2b6bc3c278f6a2fe781a1339b29fc1cb082ff1fb127543e2fbb4fae6e6f6c7113385e8414c3671cc5d1b46135593549043f5bd2ca4
7
+ data.tar.gz: 8711add62a7b3bdfe6e0bd1580b368bd21ab425718b582cc90b67497a31c3e9b32af82a95acc55ac74791bc58e9972160ed30b1add62f7f4d3225dce01a14a3e
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ZhuleiCanonicalRails
1
+ CanonicalRails
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 = 'ZhuleiCanonicalRails'
17
+ rdoc.title = 'CanonicalRails'
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 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
+ 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,8 +1,8 @@
1
- module ZhuleiCanonicalRails
1
+ module CanonicalRails
2
2
  class Engine < ::Rails::Engine
3
3
 
4
4
  initializer 'canonical_rails.add_helpers' do |app|
5
- ActionView::Base.send :include, ZhuleiCanonicalRails::TagHelper
5
+ ActionView::Base.send :include, CanonicalRails::TagHelper
6
6
  end
7
7
 
8
8
  end
@@ -1,3 +1,3 @@
1
- module ZhuleiCanonicalRails
2
- VERSION = "0.1.1"
1
+ module CanonicalRails
2
+ VERSION = "0.2.4"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require "canonical-rails/engine"
2
2
 
3
- module ZhuleiCanonicalRails
3
+ module CanonicalRails
4
4
 
5
- # Default way to setup ZhuleiCanonicalRails. Run `rails g canonical_rails:install` to create
5
+ # Default way to setup CanonicalRails. 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 ZhuleiCanonicalRails
1
+ module CanonicalRails
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
- ZhuleiCanonicalRails.setup do |config|
3
+ CanonicalRails.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.1.1
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
- - Zhu Lei
7
+ - Denis Ivanov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2018-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -86,10 +86,11 @@ dependencies:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
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.
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. '
91
92
  email:
92
- - zhuleichina@qq.com
93
+ - visible@jumph4x.net
93
94
  executables: []
94
95
  extensions: []
95
96
  extra_rdoc_files: []
@@ -124,9 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  version: '0'
125
126
  requirements: []
126
127
  rubyforge_project:
127
- rubygems_version: 2.6.14
128
+ rubygems_version: 2.5.2
128
129
  signing_key:
129
130
  specification_version: 4
130
- summary: canonical-rails by Denis Ivanov,delete the port in the url and delete the
131
- lower-case method in the code
131
+ summary: Simple and configurable Rails canonical ref tag helper
132
132
  test_files: []