au_state_select 1.8 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/au_state_select.rb +2 -14
- data/lib/au_state_select/{form_builder.rb → au_state_select_helper.rb} +0 -0
- data/lib/au_state_select/tag_helper.rb +59 -0
- data/lib/au_state_select/version.rb +1 -1
- metadata +3 -5
- data/lib/au_state_select/form_helpers.rb +0 -13
- data/lib/au_state_select/form_tag_helper.rb +0 -35
- data/lib/au_state_select/instance_tag.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d97a29dd6a625295a22db99687e10675b9be783d88269caf9ae30246511eaf75
|
4
|
+
data.tar.gz: 8de9401fdc9e66856a9acfde0f795bab2bfadb182162cffa0e9143ee3c492861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e764f6e75ca84f62ba4b8fdd5136a7f500c349ad6e6e82861f45d06cdd01c70e44acfbdbe59ca2981f3ab82c0591572097c3e3a9cb55c1621565fc05b6f292
|
7
|
+
data.tar.gz: 7feea179007bb19f454dc192942597dd4034ca5d842b30a0f9a700522e5a067f4c0e60b1ccc77a8025d260c73d56c1faa7f6c4b35cbc20bc2d57d2a8727cbbac
|
data/README.md
CHANGED
data/lib/au_state_select.rb
CHANGED
@@ -1,17 +1,5 @@
|
|
1
1
|
require "au_state_select/version"
|
2
|
-
require "au_state_select/
|
3
|
-
require
|
4
|
-
require "au_state_select/instance_tag"
|
5
|
-
require "au_state_select/form_builder"
|
6
|
-
|
7
|
-
ActionView::Base.send(:include, AUStateSelect::FormHelpers)
|
8
|
-
ActionView::Base.send(:include, AUStateSelect::FormTagHelper)
|
9
|
-
|
10
|
-
if Rails::VERSION::MAJOR >= 4
|
11
|
-
ActionView::Helpers::Tags::Select.send(:include, AUStateSelect::InstanceTag)
|
12
|
-
else
|
13
|
-
ActionView::Helpers::InstanceTag.send(:include, AUStateSelect::InstanceTag)
|
14
|
-
end
|
15
|
-
ActionView::Helpers::FormBuilder.send(:include, AUStateSelect::FormBuilder)
|
2
|
+
require "au_state_select/tag_helper"
|
3
|
+
require 'au_state_select/au_state_select_helper.rb'
|
16
4
|
|
17
5
|
require 'au_state_select/railtie' if defined?(Rails) and defined?(SimpleForm)
|
File without changes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module AUStateSelect
|
2
|
+
module TagHelper
|
3
|
+
def state_option_tags
|
4
|
+
# In Rails 5.2+, `value` accepts no arguments and must also be called
|
5
|
+
# called with parens to avoid the local variable of the same name
|
6
|
+
# https://github.com/rails/rails/pull/29791
|
7
|
+
selected_option = @options.fetch(:selected) do
|
8
|
+
if self.method(:value).arity == 0
|
9
|
+
value()
|
10
|
+
else
|
11
|
+
value(@object)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
option_tags_options = {
|
16
|
+
:selected => selected_option,
|
17
|
+
:disabled => @options[:disabled]
|
18
|
+
}
|
19
|
+
option_tags = options_for_select(state_options, option_tags_options)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def locale
|
24
|
+
@options[:locale]
|
25
|
+
end
|
26
|
+
|
27
|
+
def priority_states
|
28
|
+
@options[:priority_states]
|
29
|
+
end
|
30
|
+
|
31
|
+
def priority_countries_divider
|
32
|
+
@options[:priority_countries_divider] || "-"*15
|
33
|
+
end
|
34
|
+
|
35
|
+
def only_country_codes
|
36
|
+
@options[:only]
|
37
|
+
end
|
38
|
+
|
39
|
+
def except_country_codes
|
40
|
+
@options[:except]
|
41
|
+
end
|
42
|
+
|
43
|
+
def format
|
44
|
+
@options[:format] || :default
|
45
|
+
end
|
46
|
+
|
47
|
+
def state_options
|
48
|
+
if @options.key?(:short_name) && @options[:short_name]
|
49
|
+
['ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA']
|
50
|
+
else
|
51
|
+
[['Australian Capital Territory', 'ACT'],['New South Wales', 'NSW'],['Northern Territory', 'NT'],['Queensland', 'QLD'],['South Australia', 'SA'],['Tasmania', 'TAS'],['Victoria', 'VIC'],['Western Australia', 'WA']]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def html_safe_newline
|
56
|
+
"\n".html_safe
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: au_state_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '2.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Zhang
|
@@ -52,11 +52,9 @@ files:
|
|
52
52
|
- Rakefile
|
53
53
|
- au_state_select.gemspec
|
54
54
|
- lib/au_state_select.rb
|
55
|
-
- lib/au_state_select/
|
56
|
-
- lib/au_state_select/form_helpers.rb
|
57
|
-
- lib/au_state_select/form_tag_helper.rb
|
58
|
-
- lib/au_state_select/instance_tag.rb
|
55
|
+
- lib/au_state_select/au_state_select_helper.rb
|
59
56
|
- lib/au_state_select/railtie.rb
|
57
|
+
- lib/au_state_select/tag_helper.rb
|
60
58
|
- lib/au_state_select/version.rb
|
61
59
|
homepage: ''
|
62
60
|
licenses:
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module AUStateSelect
|
2
|
-
module FormHelpers
|
3
|
-
def state_select(object_name, method, priority_countries = nil, options = {}, html_options = {})
|
4
|
-
if Rails::VERSION::MAJOR >= 4
|
5
|
-
instance_tag = ActionView::Helpers::Tags::Select.new(object_name, method, self, [], options, html_options)
|
6
|
-
instance_tag.to_state_select_tag(priority_countries, html_options)
|
7
|
-
else
|
8
|
-
instance_tag = ActionView::Helpers::InstanceTag.new(object_name, method, self, options.delete(:object))
|
9
|
-
instance_tag.to_state_select_tag(priority_countries, html_options, options)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module AUStateSelect
|
2
|
-
module FormTagHelper
|
3
|
-
def state_select_tag(name, options = {}, html_options = {})
|
4
|
-
|
5
|
-
states = ""
|
6
|
-
|
7
|
-
if options.present? and (options[:include_blank] or (options[:prompt]))
|
8
|
-
if options[:include_blank].present?
|
9
|
-
option = options[:include_blank] == true ? "" : options[:include_blank]
|
10
|
-
elsif options[:prompt].present?
|
11
|
-
option = options[:prompt] == true ? "Please Select" : options[:prompt]
|
12
|
-
end
|
13
|
-
states += "<option value>#{option}</option>\n"
|
14
|
-
end
|
15
|
-
|
16
|
-
select_options = if options.key?(:short_name) and options[:short_name]
|
17
|
-
['ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA']
|
18
|
-
else
|
19
|
-
[['Australian Capital Territory', 'ACT'],['New South Wales', 'NSW'],['Northern Territory', 'NT'],['Queensland', 'QLD'],['South Australia', 'SA'],['Tasmania', 'TAS'],['Victoria', 'VIC'],['Western Australia', 'WA']]
|
20
|
-
end
|
21
|
-
|
22
|
-
if options.key?(:value) and options[:value]
|
23
|
-
states = states + options_for_select(select_options, options[:value])
|
24
|
-
else
|
25
|
-
states = states + options_for_select(select_options)
|
26
|
-
end
|
27
|
-
|
28
|
-
html_options = html_options.stringify_keys
|
29
|
-
|
30
|
-
attribute_id = options[:id] || name
|
31
|
-
|
32
|
-
content_tag(:select, states.html_safe, { "name" => name, "id" => sanitize_to_id(attribute_id) }.update(html_options.stringify_keys))
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module AUStateSelect
|
2
|
-
|
3
|
-
module InstanceTag
|
4
|
-
def to_state_select_tag(priority_states, html_options = {}, options = {})
|
5
|
-
# Rails 4 stores options sent when creating an InstanceTag.
|
6
|
-
# Let's use them!
|
7
|
-
options = @options if defined?(@options)
|
8
|
-
|
9
|
-
state_select(priority_states, options, html_options)
|
10
|
-
end
|
11
|
-
|
12
|
-
def state_select(priority_states, options, html_options)
|
13
|
-
selected = object.send(@method_name) if object.respond_to?(@method_name)
|
14
|
-
|
15
|
-
states = ""
|
16
|
-
|
17
|
-
if options.present? and (options[:include_blank] or (options[:prompt] and !selected))
|
18
|
-
if options[:include_blank].present?
|
19
|
-
option = options[:include_blank] == true ? "" : options[:include_blank]
|
20
|
-
elsif options[:prompt].present?
|
21
|
-
option = options[:prompt] == true ? "Please Select" : options[:prompt]
|
22
|
-
end
|
23
|
-
states += "<option value>#{option}</option>\n"
|
24
|
-
end
|
25
|
-
|
26
|
-
if priority_states
|
27
|
-
states += options_for_select(priority_states, selected)
|
28
|
-
states += "<option value=\"\" disabled=\"disabled\">-------------</option>\n"
|
29
|
-
end
|
30
|
-
|
31
|
-
select_options = if options.key?(:short_name) and options[:short_name]
|
32
|
-
['ACT', 'NSW', 'NT', 'QLD', 'SA', 'TAS', 'VIC', 'WA']
|
33
|
-
else
|
34
|
-
[['Australian Capital Territory', 'ACT'],['New South Wales', 'NSW'],['Northern Territory', 'NT'],['Queensland', 'QLD'],['South Australia', 'SA'],['Tasmania', 'TAS'],['Victoria', 'VIC'],['Western Australia', 'WA']]
|
35
|
-
end
|
36
|
-
states = states + options_for_select(select_options, selected)
|
37
|
-
|
38
|
-
html_options = html_options.stringify_keys
|
39
|
-
add_default_name_and_id(html_options)
|
40
|
-
|
41
|
-
content_tag(:select, states.html_safe, html_options)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|