country_select 8.0.1 → 8.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,64 +1,69 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- country_select (8.0.1)
4
+ country_select (8.0.3)
5
5
  countries (~> 5.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (7.0.4)
11
- actionview (= 7.0.4)
12
- activesupport (= 7.0.4)
13
- rack (~> 2.0, >= 2.2.0)
10
+ actionpack (7.0.8)
11
+ actionview (= 7.0.8)
12
+ activesupport (= 7.0.8)
13
+ rack (~> 2.0, >= 2.2.4)
14
14
  rack-test (>= 0.6.3)
15
15
  rails-dom-testing (~> 2.0)
16
16
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
- actionview (7.0.4)
18
- activesupport (= 7.0.4)
17
+ actionview (7.0.8)
18
+ activesupport (= 7.0.8)
19
19
  builder (~> 3.1)
20
20
  erubi (~> 1.4)
21
21
  rails-dom-testing (~> 2.0)
22
22
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activesupport (7.0.4)
23
+ activesupport (7.0.8)
24
24
  concurrent-ruby (~> 1.0, >= 1.0.2)
25
25
  i18n (>= 1.6, < 2)
26
26
  minitest (>= 5.1)
27
27
  tzinfo (~> 2.0)
28
28
  builder (3.2.4)
29
29
  coderay (1.1.3)
30
- concurrent-ruby (1.1.10)
31
- countries (5.3.0)
30
+ concurrent-ruby (1.2.2)
31
+ countries (5.6.0)
32
32
  unaccent (~> 0.3)
33
33
  crass (1.0.6)
34
34
  diff-lcs (1.5.0)
35
+ docile (1.4.0)
35
36
  erubi (1.12.0)
36
- i18n (1.12.0)
37
+ i18n (1.14.1)
37
38
  concurrent-ruby (~> 1.0)
38
- loofah (2.19.1)
39
+ loofah (2.21.3)
39
40
  crass (~> 1.0.2)
40
- nokogiri (>= 1.5.9)
41
+ nokogiri (>= 1.12.0)
41
42
  method_source (1.0.0)
42
- minitest (5.17.0)
43
- nokogiri (1.14.0.rc1-x86_64-darwin)
43
+ minitest (5.20.0)
44
+ nokogiri (1.15.4-arm64-darwin)
44
45
  racc (~> 1.4)
45
- nokogiri (1.14.0.rc1-x86_64-linux)
46
+ nokogiri (1.15.4-x86_64-darwin)
46
47
  racc (~> 1.4)
47
- pry (0.14.1)
48
+ nokogiri (1.15.4-x86_64-linux)
49
+ racc (~> 1.4)
50
+ pry (0.14.2)
48
51
  coderay (~> 1.1)
49
52
  method_source (~> 1.0)
50
- racc (1.6.2)
51
- rack (2.2.5)
52
- rack-test (2.0.2)
53
+ racc (1.7.1)
54
+ rack (2.2.8)
55
+ rack-test (2.1.0)
53
56
  rack (>= 1.3)
54
- rails-dom-testing (2.0.3)
55
- activesupport (>= 4.2.0)
57
+ rails-dom-testing (2.2.0)
58
+ activesupport (>= 5.0.0)
59
+ minitest
56
60
  nokogiri (>= 1.6)
57
- rails-html-sanitizer (1.4.4)
58
- loofah (~> 2.19, >= 2.19.1)
59
- railties (7.0.4)
60
- actionpack (= 7.0.4)
61
- activesupport (= 7.0.4)
61
+ rails-html-sanitizer (1.6.0)
62
+ loofah (~> 2.21)
63
+ nokogiri (~> 1.14)
64
+ railties (7.0.8)
65
+ actionpack (= 7.0.8)
66
+ activesupport (= 7.0.8)
62
67
  method_source
63
68
  rake (>= 12.2)
64
69
  thor (~> 1.0)
@@ -68,33 +73,41 @@ GEM
68
73
  rspec-core (~> 3.12.0)
69
74
  rspec-expectations (~> 3.12.0)
70
75
  rspec-mocks (~> 3.12.0)
71
- rspec-core (3.12.0)
76
+ rspec-core (3.12.2)
72
77
  rspec-support (~> 3.12.0)
73
- rspec-expectations (3.12.1)
78
+ rspec-expectations (3.12.3)
74
79
  diff-lcs (>= 1.2.0, < 2.0)
75
80
  rspec-support (~> 3.12.0)
76
- rspec-mocks (3.12.1)
81
+ rspec-mocks (3.12.6)
77
82
  diff-lcs (>= 1.2.0, < 2.0)
78
83
  rspec-support (~> 3.12.0)
79
- rspec-support (3.12.0)
80
- thor (1.2.1)
81
- tzinfo (2.0.5)
84
+ rspec-support (3.12.1)
85
+ simplecov (0.22.0)
86
+ docile (~> 1.1)
87
+ simplecov-html (~> 0.11)
88
+ simplecov_json_formatter (~> 0.1)
89
+ simplecov-html (0.12.3)
90
+ simplecov_json_formatter (0.1.4)
91
+ thor (1.2.2)
92
+ tzinfo (2.0.6)
82
93
  concurrent-ruby (~> 1.0)
83
94
  unaccent (0.4.0)
84
- zeitwerk (2.6.6)
95
+ zeitwerk (2.6.12)
85
96
 
86
97
  PLATFORMS
98
+ arm64-darwin-22
87
99
  x86_64-darwin-22
88
100
  x86_64-linux
89
101
 
90
102
  DEPENDENCIES
91
103
  actionpack (~> 7.0.0)
92
104
  country_select!
93
- nokogiri (= 1.14.0.rc1)
105
+ nokogiri (~> 1.15)
94
106
  pry (~> 0)
95
107
  railties (~> 7.0.0)
96
108
  rake (~> 13)
97
109
  rspec (~> 3)
110
+ simplecov (~> 0.22)
98
111
 
99
112
  BUNDLED WITH
100
- 2.4.2
113
+ 2.4.19
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec path: '../'
6
+
7
+ gem 'railties', '~> 7.1.0'
8
+ gem 'actionpack', '~> 7.1.0'
9
+ gem 'nokogiri', '~> 1.15'
@@ -0,0 +1,145 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ country_select (8.0.3)
5
+ countries (~> 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (7.1.0)
11
+ actionview (= 7.1.0)
12
+ activesupport (= 7.1.0)
13
+ nokogiri (>= 1.8.5)
14
+ rack (>= 2.2.4)
15
+ rack-session (>= 1.0.1)
16
+ rack-test (>= 0.6.3)
17
+ rails-dom-testing (~> 2.2)
18
+ rails-html-sanitizer (~> 1.6)
19
+ actionview (7.1.0)
20
+ activesupport (= 7.1.0)
21
+ builder (~> 3.1)
22
+ erubi (~> 1.11)
23
+ rails-dom-testing (~> 2.2)
24
+ rails-html-sanitizer (~> 1.6)
25
+ activesupport (7.1.0)
26
+ base64
27
+ bigdecimal
28
+ concurrent-ruby (~> 1.0, >= 1.0.2)
29
+ connection_pool (>= 2.2.5)
30
+ drb
31
+ i18n (>= 1.6, < 2)
32
+ minitest (>= 5.1)
33
+ mutex_m
34
+ tzinfo (~> 2.0)
35
+ base64 (0.1.1)
36
+ bigdecimal (3.1.4)
37
+ builder (3.2.4)
38
+ coderay (1.1.3)
39
+ concurrent-ruby (1.2.2)
40
+ connection_pool (2.4.1)
41
+ countries (5.6.0)
42
+ unaccent (~> 0.3)
43
+ crass (1.0.6)
44
+ diff-lcs (1.5.0)
45
+ docile (1.4.0)
46
+ drb (2.1.1)
47
+ ruby2_keywords
48
+ erubi (1.12.0)
49
+ i18n (1.14.1)
50
+ concurrent-ruby (~> 1.0)
51
+ io-console (0.6.0)
52
+ irb (1.8.1)
53
+ rdoc
54
+ reline (>= 0.3.8)
55
+ loofah (2.21.3)
56
+ crass (~> 1.0.2)
57
+ nokogiri (>= 1.12.0)
58
+ method_source (1.0.0)
59
+ minitest (5.20.0)
60
+ mutex_m (0.1.2)
61
+ nokogiri (1.15.4-arm64-darwin)
62
+ racc (~> 1.4)
63
+ nokogiri (1.15.4-x86_64-darwin)
64
+ racc (~> 1.4)
65
+ nokogiri (1.15.4-x86_64-linux)
66
+ racc (~> 1.4)
67
+ pry (0.14.2)
68
+ coderay (~> 1.1)
69
+ method_source (~> 1.0)
70
+ psych (5.1.0)
71
+ stringio
72
+ racc (1.7.1)
73
+ rack (3.0.8)
74
+ rack-session (2.0.0)
75
+ rack (>= 3.0.0)
76
+ rack-test (2.1.0)
77
+ rack (>= 1.3)
78
+ rackup (2.1.0)
79
+ rack (>= 3)
80
+ webrick (~> 1.8)
81
+ rails-dom-testing (2.2.0)
82
+ activesupport (>= 5.0.0)
83
+ minitest
84
+ nokogiri (>= 1.6)
85
+ rails-html-sanitizer (1.6.0)
86
+ loofah (~> 2.21)
87
+ nokogiri (~> 1.14)
88
+ railties (7.1.0)
89
+ actionpack (= 7.1.0)
90
+ activesupport (= 7.1.0)
91
+ irb
92
+ rackup (>= 1.0.0)
93
+ rake (>= 12.2)
94
+ thor (~> 1.0, >= 1.2.2)
95
+ zeitwerk (~> 2.6)
96
+ rake (13.0.6)
97
+ rdoc (6.5.0)
98
+ psych (>= 4.0.0)
99
+ reline (0.3.9)
100
+ io-console (~> 0.5)
101
+ rspec (3.12.0)
102
+ rspec-core (~> 3.12.0)
103
+ rspec-expectations (~> 3.12.0)
104
+ rspec-mocks (~> 3.12.0)
105
+ rspec-core (3.12.2)
106
+ rspec-support (~> 3.12.0)
107
+ rspec-expectations (3.12.3)
108
+ diff-lcs (>= 1.2.0, < 2.0)
109
+ rspec-support (~> 3.12.0)
110
+ rspec-mocks (3.12.6)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.12.0)
113
+ rspec-support (3.12.1)
114
+ ruby2_keywords (0.0.5)
115
+ simplecov (0.22.0)
116
+ docile (~> 1.1)
117
+ simplecov-html (~> 0.11)
118
+ simplecov_json_formatter (~> 0.1)
119
+ simplecov-html (0.12.3)
120
+ simplecov_json_formatter (0.1.4)
121
+ stringio (3.0.8)
122
+ thor (1.2.2)
123
+ tzinfo (2.0.6)
124
+ concurrent-ruby (~> 1.0)
125
+ unaccent (0.4.0)
126
+ webrick (1.8.1)
127
+ zeitwerk (2.6.12)
128
+
129
+ PLATFORMS
130
+ arm64-darwin-22
131
+ x86_64-darwin-22
132
+ x86_64-linux
133
+
134
+ DEPENDENCIES
135
+ actionpack (~> 7.1.0)
136
+ country_select!
137
+ nokogiri (~> 1.15)
138
+ pry (~> 0)
139
+ railties (~> 7.1.0)
140
+ rake (~> 13)
141
+ rspec (~> 3)
142
+ simplecov (~> 0.22)
143
+
144
+ BUNDLED WITH
145
+ 2.4.19
@@ -1,15 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActionView
2
4
  module Helpers
3
5
  class FormBuilder
4
6
  def country_select(method, priority_or_options = {}, options = {}, html_options = {})
5
- if Hash === priority_or_options
7
+ if priority_or_options.is_a? Hash
6
8
  html_options = options
7
9
  options = priority_or_options
8
10
  else
9
11
  if RUBY_VERSION =~ /^3\.\d\.\d/
10
- warn "DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. Please use the `priority_countries:` option.", uplevel: 1, category: :deprecated
12
+ warn 'DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. \
13
+ Please use the `priority_countries:` option.', uplevel: 1, category: :deprecated
11
14
  else
12
- warn "DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. Please use the `priority_countries:` option.", uplevel: 1
15
+ warn 'DEPRECATION WARNING: Setting priority countries with the 1.x syntax is deprecated. \
16
+ Please use the `priority_countries:` option.', uplevel: 1
13
17
  end
14
18
  options[:priority_countries] = priority_or_options
15
19
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CountrySelect
2
4
  DEFAULTS = {
3
5
  except: nil,
@@ -5,7 +7,7 @@ module CountrySelect
5
7
  locale: nil,
6
8
  only: nil,
7
9
  priority_countries: nil,
8
- priority_countries_divider: "-" * 15,
10
+ priority_countries_divider: '-' * 15,
9
11
  sort_provided: true
10
12
  }
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CountrySelect
2
4
  FORMATS = {}
3
5
 
@@ -1,12 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CountrySelect
2
- class CountryNotFoundError < StandardError;end
4
+ class CountryNotFoundError < StandardError; end
5
+
3
6
  module TagHelper
7
+ unless respond_to?(:options_for_select)
8
+ include ActionView::Helpers::FormOptionsHelper
9
+ include ActionView::Helpers::Tags::SelectRenderer if defined?(ActionView::Helpers::Tags::SelectRenderer)
10
+ end
11
+
4
12
  def country_option_tags
5
13
  # In Rails 5.2+, `value` accepts no arguments and must also be called
6
14
  # with parens to avoid the local variable of the same name
7
15
  # https://github.com/rails/rails/pull/29791
8
16
  selected_option = @options.fetch(:selected) do
9
- if self.method(:value).arity == 0
17
+ if self.method(:value).arity.zero?
10
18
  value()
11
19
  else
12
20
  value(@object)
@@ -14,26 +22,19 @@ module CountrySelect
14
22
  end
15
23
 
16
24
  option_tags_options = {
17
- :selected => selected_option,
18
- :disabled => @options[:disabled]
25
+ selected: selected_option,
26
+ disabled: @options[:disabled]
19
27
  }
20
28
 
21
29
  if priority_countries.present?
22
- priority_countries_options = country_options_for(priority_countries, @options.fetch(:sort_provided, ::CountrySelect::DEFAULTS[:sort_provided]))
23
-
24
- option_tags = options_for_select(priority_countries_options, option_tags_options)
25
- option_tags += html_safe_newline + options_for_select([priority_countries_divider], disabled: priority_countries_divider)
26
-
27
- option_tags_options[:selected] = [option_tags_options[:selected]] unless option_tags_options[:selected].kind_of?(Array)
28
- option_tags_options[:selected].delete_if{|selected| priority_countries_options.map(&:second).include?(selected)}
29
-
30
- option_tags += html_safe_newline + options_for_select(country_options, option_tags_options)
30
+ options_for_select_with_priority_countries(country_options, option_tags_options)
31
31
  else
32
- option_tags = options_for_select(country_options, option_tags_options)
32
+ options_for_select(country_options, option_tags_options)
33
33
  end
34
34
  end
35
35
 
36
36
  private
37
+
37
38
  def locale
38
39
  @options.fetch(:locale, ::CountrySelect::DEFAULTS[:locale])
39
40
  end
@@ -59,54 +60,63 @@ module CountrySelect
59
60
  end
60
61
 
61
62
  def country_options
63
+ codes = ISO3166::Country.codes
64
+
62
65
  if only_country_codes.present?
63
- codes = only_country_codes & ISO3166::Country.codes
66
+ codes = only_country_codes & codes
64
67
  sort = @options.fetch(:sort_provided, ::CountrySelect::DEFAULTS[:sort_provided])
65
- elsif except_country_codes.present?
66
- codes = ISO3166::Country.codes - except_country_codes
67
- sort = true
68
68
  else
69
- codes = ISO3166::Country.codes
69
+ codes -= except_country_codes if except_country_codes.present?
70
70
  sort = true
71
71
  end
72
72
 
73
- country_options_for(codes, sort)
73
+ country_options_for(codes, sorted: sort)
74
74
  end
75
75
 
76
- def country_options_for(country_codes, sorted=true)
76
+ def country_options_for(country_codes, sorted: true)
77
77
  I18n.with_locale(locale) do
78
- country_list = country_codes.map do |code_or_name|
79
- if country = ISO3166::Country.new(code_or_name)
80
- code = country.alpha2
81
- elsif country = ISO3166::Country.find_country_by_any_name(code_or_name)
82
- code = country.alpha2
83
- end
84
-
85
- unless country.present?
86
- msg = "Could not find Country with string '#{code_or_name}'"
87
- raise CountryNotFoundError.new(msg)
88
- end
89
-
90
- formatted_country = ::CountrySelect::FORMATS[format].call(country)
91
-
92
- if formatted_country.is_a?(Array)
93
- formatted_country
94
- else
95
- [formatted_country, code]
96
- end
78
+ country_list = country_codes.map { |code_or_name| get_formatted_country(code_or_name) }
97
79
 
98
- end
80
+ country_list.sort_by! { |name, _| [I18n.transliterate(name.to_s), name] } if sorted
81
+ country_list
82
+ end
83
+ end
99
84
 
100
- if sorted
101
- country_list.sort_by { |name, code| [I18n.transliterate(name), name] }
102
- else
103
- country_list
104
- end
85
+ def options_for_select_with_priority_countries(country_options, tags_options)
86
+ sorted = @options.fetch(:sort_provided, ::CountrySelect::DEFAULTS[:sort_provided])
87
+ priority_countries_options = country_options_for(priority_countries, sorted: sorted)
88
+
89
+ option_tags = priority_options_for_select(priority_countries_options, tags_options)
90
+
91
+ tags_options[:selected] = Array(tags_options[:selected]).delete_if do |selected|
92
+ priority_countries_options.map(&:second).include?(selected)
105
93
  end
94
+
95
+ option_tags += "\n".html_safe + options_for_select(country_options, tags_options)
96
+
97
+ option_tags
106
98
  end
107
99
 
108
- def html_safe_newline
109
- "\n".html_safe
100
+ def priority_options_for_select(priority_countries_options, tags_options)
101
+ option_tags = options_for_select(priority_countries_options, tags_options)
102
+ option_tags += "\n".html_safe +
103
+ options_for_select([priority_countries_divider], disabled: priority_countries_divider)
104
+ end
105
+
106
+ def get_formatted_country(code_or_name)
107
+ country = ISO3166::Country.new(code_or_name) ||
108
+ ISO3166::Country.find_country_by_any_name(code_or_name)
109
+
110
+ raise(CountryNotFoundError, "Could not find Country with string '#{code_or_name}'") unless country.present?
111
+
112
+ code = country.alpha2
113
+ formatted_country = ::CountrySelect::FORMATS[format].call(country)
114
+
115
+ if formatted_country.is_a?(Array)
116
+ formatted_country
117
+ else
118
+ [formatted_country, code]
119
+ end
110
120
  end
111
121
  end
112
122
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CountrySelect
2
- VERSION = '8.0.1'
4
+ VERSION = '8.0.3'
3
5
  end
@@ -1,4 +1,4 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  require 'countries'
4
4