trusty-cms 4.1.9 → 4.2

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.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +70 -67
  3. data/lib/trusty_cms.rb +1 -1
  4. data/trusty_cms.gemspec +2 -2
  5. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/base.rb +195 -0
  6. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/check_box.rb +65 -0
  7. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/checkable.rb +18 -0
  8. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/collection_check_boxes.rb +35 -0
  9. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/collection_helpers.rb +118 -0
  10. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/collection_radio_buttons.rb +30 -0
  11. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/collection_select.rb +30 -0
  12. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/color_field.rb +26 -0
  13. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/date_field.rb +14 -0
  14. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/date_select.rb +73 -0
  15. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/datetime_field.rb +31 -0
  16. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/datetime_local_field.rb +20 -0
  17. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/datetime_select.rb +10 -0
  18. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/email_field.rb +10 -0
  19. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/file_field.rb +10 -0
  20. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/grouped_collection_select.rb +31 -0
  21. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/hidden_field.rb +10 -0
  22. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/label.rb +80 -0
  23. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/month_field.rb +14 -0
  24. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/number_field.rb +20 -0
  25. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/password_field.rb +14 -0
  26. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/placeholderable.rb +24 -0
  27. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/radio_button.rb +32 -0
  28. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/range_field.rb +10 -0
  29. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/search_field.rb +27 -0
  30. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/select.rb +42 -0
  31. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/tel_field.rb +10 -0
  32. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/text_area.rb +24 -0
  33. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/text_field.rb +33 -0
  34. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/time_field.rb +14 -0
  35. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/time_select.rb +10 -0
  36. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/time_zone_select.rb +22 -0
  37. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/translator.rb +39 -0
  38. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/url_field.rb +10 -0
  39. data/vendor/bundle/ruby/2.6.0/gems/actionview-6.0.3.4/lib/action_view/helpers/tags/week_field.rb +14 -0
  40. metadata +164 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4fb05c8f28c0097f216371ee9b64551430ef41f134939c45db99af078f16a909
4
- data.tar.gz: a774319265c2377af1242e05337c59e5310188f7259330adcf56e138407c9a32
3
+ metadata.gz: 299f6d4ea4f8354fc95eca5057d85ef469ecf514a9b9caccea05498f3ee7b3db
4
+ data.tar.gz: 9c635ae0f8cb03af87e45321f6f139cdab67abea7ad57d5bb304c3bbb5426204
5
5
  SHA512:
6
- metadata.gz: b77c5e66a0793e654d506cf7b07fda3e04b90869e515e181e6a96c42659e65876d2dfe0d436f8ef6aa8bd1a14cbfa1136f0a21a92a99912edaefb8d545c76885
7
- data.tar.gz: 0eee0cbdcc348c0ea3a5c9167c7622eba56a88ebf02d3430ba31b92020e780da3889f01179bcc07ff235f8fa2ea6a47d2ffd99189c4a431b779d69866a420de5
6
+ metadata.gz: 41043b6945a24d689aefc362b5eed571b0cb378aaffb9b3dcf67f4570fba089b86062341998e7d54ecc53391d74cab0f7e76af6de131a9743976227f47b5c5a8
7
+ data.tar.gz: cc491f12651bc85e7fddc1612319882c5b9982fe4dc4bce72d5b4325cbfbf597786a2e06ab8cabbbb1bf2453a515590ec62ddd719e76a4efae1984d6bb77ffa1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trusty-cms (4.1.9)
4
+ trusty-cms (4.2)
5
5
  RedCloth (= 4.3.2)
6
6
  acts_as_list (>= 0.9.5, < 1.1.0)
7
7
  acts_as_tree (>= 2.6.1, < 2.9.0)
@@ -9,8 +9,8 @@ PATH
9
9
  delocalize (>= 0.2, < 2.0)
10
10
  devise
11
11
  execjs (~> 2.7)
12
- haml (~> 5.0)
13
- haml-rails (~> 1.0.0)
12
+ haml
13
+ haml-rails
14
14
  highline (>= 1.7.8, < 2.1.0)
15
15
  kraken-io
16
16
  mini_racer
@@ -34,61 +34,65 @@ GEM
34
34
  remote: https://rubygems.org/
35
35
  specs:
36
36
  RedCloth (4.3.2)
37
- actioncable (6.0.3.4)
38
- actionpack (= 6.0.3.4)
37
+ actioncable (6.1.1)
38
+ actionpack (= 6.1.1)
39
+ activesupport (= 6.1.1)
39
40
  nio4r (~> 2.0)
40
41
  websocket-driver (>= 0.6.1)
41
- actionmailbox (6.0.3.4)
42
- actionpack (= 6.0.3.4)
43
- activejob (= 6.0.3.4)
44
- activerecord (= 6.0.3.4)
45
- activestorage (= 6.0.3.4)
46
- activesupport (= 6.0.3.4)
42
+ actionmailbox (6.1.1)
43
+ actionpack (= 6.1.1)
44
+ activejob (= 6.1.1)
45
+ activerecord (= 6.1.1)
46
+ activestorage (= 6.1.1)
47
+ activesupport (= 6.1.1)
47
48
  mail (>= 2.7.1)
48
- actionmailer (6.0.3.4)
49
- actionpack (= 6.0.3.4)
50
- actionview (= 6.0.3.4)
51
- activejob (= 6.0.3.4)
49
+ actionmailer (6.1.1)
50
+ actionpack (= 6.1.1)
51
+ actionview (= 6.1.1)
52
+ activejob (= 6.1.1)
53
+ activesupport (= 6.1.1)
52
54
  mail (~> 2.5, >= 2.5.4)
53
55
  rails-dom-testing (~> 2.0)
54
- actionpack (6.0.3.4)
55
- actionview (= 6.0.3.4)
56
- activesupport (= 6.0.3.4)
57
- rack (~> 2.0, >= 2.0.8)
56
+ actionpack (6.1.1)
57
+ actionview (= 6.1.1)
58
+ activesupport (= 6.1.1)
59
+ rack (~> 2.0, >= 2.0.9)
58
60
  rack-test (>= 0.6.3)
59
61
  rails-dom-testing (~> 2.0)
60
62
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
61
- actiontext (6.0.3.4)
62
- actionpack (= 6.0.3.4)
63
- activerecord (= 6.0.3.4)
64
- activestorage (= 6.0.3.4)
65
- activesupport (= 6.0.3.4)
63
+ actiontext (6.1.1)
64
+ actionpack (= 6.1.1)
65
+ activerecord (= 6.1.1)
66
+ activestorage (= 6.1.1)
67
+ activesupport (= 6.1.1)
66
68
  nokogiri (>= 1.8.5)
67
- actionview (6.0.3.4)
68
- activesupport (= 6.0.3.4)
69
+ actionview (6.1.1)
70
+ activesupport (= 6.1.1)
69
71
  builder (~> 3.1)
70
72
  erubi (~> 1.4)
71
73
  rails-dom-testing (~> 2.0)
72
74
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
73
- activejob (6.0.3.4)
74
- activesupport (= 6.0.3.4)
75
+ activejob (6.1.1)
76
+ activesupport (= 6.1.1)
75
77
  globalid (>= 0.3.6)
76
- activemodel (6.0.3.4)
77
- activesupport (= 6.0.3.4)
78
- activerecord (6.0.3.4)
79
- activemodel (= 6.0.3.4)
80
- activesupport (= 6.0.3.4)
81
- activestorage (6.0.3.4)
82
- actionpack (= 6.0.3.4)
83
- activejob (= 6.0.3.4)
84
- activerecord (= 6.0.3.4)
78
+ activemodel (6.1.1)
79
+ activesupport (= 6.1.1)
80
+ activerecord (6.1.1)
81
+ activemodel (= 6.1.1)
82
+ activesupport (= 6.1.1)
83
+ activestorage (6.1.1)
84
+ actionpack (= 6.1.1)
85
+ activejob (= 6.1.1)
86
+ activerecord (= 6.1.1)
87
+ activesupport (= 6.1.1)
85
88
  marcel (~> 0.3.1)
86
- activesupport (6.0.3.4)
89
+ mimemagic (~> 0.3.2)
90
+ activesupport (6.1.1)
87
91
  concurrent-ruby (~> 1.0, >= 1.0.2)
88
- i18n (>= 0.7, < 2)
89
- minitest (~> 5.1)
90
- tzinfo (~> 1.1)
91
- zeitwerk (~> 2.2, >= 2.2.2)
92
+ i18n (>= 1.6, < 2)
93
+ minitest (>= 5.1)
94
+ tzinfo (~> 2.0)
95
+ zeitwerk (~> 2.3)
92
96
  acts_as_list (1.0.3)
93
97
  activerecord (>= 4.2)
94
98
  acts_as_tree (2.8.0)
@@ -143,12 +147,12 @@ GEM
143
147
  haml (5.2.1)
144
148
  temple (>= 0.8.0)
145
149
  tilt
146
- haml-rails (1.0.0)
147
- actionpack (>= 4.0.1)
148
- activesupport (>= 4.0.1)
150
+ haml-rails (2.0.1)
151
+ actionpack (>= 5.1)
152
+ activesupport (>= 5.1)
149
153
  haml (>= 4.0.6, < 6.0)
150
154
  html2haml (>= 1.0.1)
151
- railties (>= 4.0.1)
155
+ railties (>= 5.1)
152
156
  highline (2.0.3)
153
157
  html2haml (2.2.0)
154
158
  erubis (~> 2.7.0)
@@ -218,20 +222,20 @@ GEM
218
222
  rack-test (1.1.0)
219
223
  rack (>= 1.0, < 3)
220
224
  radius (0.7.5)
221
- rails (6.0.3.4)
222
- actioncable (= 6.0.3.4)
223
- actionmailbox (= 6.0.3.4)
224
- actionmailer (= 6.0.3.4)
225
- actionpack (= 6.0.3.4)
226
- actiontext (= 6.0.3.4)
227
- actionview (= 6.0.3.4)
228
- activejob (= 6.0.3.4)
229
- activemodel (= 6.0.3.4)
230
- activerecord (= 6.0.3.4)
231
- activestorage (= 6.0.3.4)
232
- activesupport (= 6.0.3.4)
233
- bundler (>= 1.3.0)
234
- railties (= 6.0.3.4)
225
+ rails (6.1.1)
226
+ actioncable (= 6.1.1)
227
+ actionmailbox (= 6.1.1)
228
+ actionmailer (= 6.1.1)
229
+ actionpack (= 6.1.1)
230
+ actiontext (= 6.1.1)
231
+ actionview (= 6.1.1)
232
+ activejob (= 6.1.1)
233
+ activemodel (= 6.1.1)
234
+ activerecord (= 6.1.1)
235
+ activestorage (= 6.1.1)
236
+ activesupport (= 6.1.1)
237
+ bundler (>= 1.15.0)
238
+ railties (= 6.1.1)
235
239
  sprockets-rails (>= 2.0.0)
236
240
  rails-dom-testing (2.0.3)
237
241
  activesupport (>= 4.2.0)
@@ -240,12 +244,12 @@ GEM
240
244
  loofah (~> 2.3)
241
245
  rails-observers (0.1.5)
242
246
  activemodel (>= 4.0)
243
- railties (6.0.3.4)
244
- actionpack (= 6.0.3.4)
245
- activesupport (= 6.0.3.4)
247
+ railties (6.1.1)
248
+ actionpack (= 6.1.1)
249
+ activesupport (= 6.1.1)
246
250
  method_source
247
251
  rake (>= 0.8.7)
248
- thor (>= 0.20.3, < 2.0)
252
+ thor (~> 1.0)
249
253
  rake (13.0.3)
250
254
  rdoc (6.3.0)
251
255
  regexp_parser (1.8.2)
@@ -304,12 +308,11 @@ GEM
304
308
  terrapin (0.6.0)
305
309
  climate_control (>= 0.0.3, < 1.0)
306
310
  thor (1.0.1)
307
- thread_safe (0.3.6)
308
311
  tilt (2.0.10)
309
312
  trustygems (0.2.1)
310
313
  rake
311
- tzinfo (1.2.9)
312
- thread_safe (~> 0.1)
314
+ tzinfo (2.0.4)
315
+ concurrent-ruby (~> 1.0)
313
316
  uglifier (4.2.0)
314
317
  execjs (>= 0.3.0, < 3)
315
318
  uuidtools (2.2.0)
@@ -2,6 +2,6 @@ TRUSTY_CMS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) unle
2
2
 
3
3
  unless defined? TrustyCms::VERSION
4
4
  module TrustyCms
5
- VERSION = '4.1.9'.freeze
5
+ VERSION = '4.2'.freeze
6
6
  end
7
7
  end
@@ -29,8 +29,8 @@ a general purpose content managment system--not merely a blogging engine.'
29
29
  s.add_dependency 'delocalize', '>= 0.2', '< 2.0'
30
30
  s.add_dependency 'devise'
31
31
  s.add_dependency 'execjs', '~> 2.7'
32
- s.add_dependency 'haml', '~> 5.0'
33
- s.add_dependency 'haml-rails', '~> 1.0.0'
32
+ s.add_dependency 'haml'
33
+ s.add_dependency 'haml-rails'
34
34
  s.add_dependency 'highline', '>= 1.7.8', '< 2.1.0'
35
35
  s.add_dependency 'kraken-io'
36
36
  s.add_dependency 'mini_racer'
@@ -0,0 +1,195 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActionView
4
+ module Helpers
5
+ module Tags # :nodoc:
6
+ class Base # :nodoc:
7
+ include Helpers::ActiveModelInstanceTag, Helpers::TagHelper, Helpers::FormTagHelper
8
+ include FormOptionsHelper
9
+
10
+ attr_reader :object
11
+
12
+ def initialize(object_name, method_name, template_object, options = {})
13
+ @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup
14
+ @template_object = template_object
15
+
16
+ @object_name.sub!(/\[\]$/, "") || @object_name.sub!(/\[\]\]$/, "]")
17
+ @object = retrieve_object(options.delete(:object))
18
+ @skip_default_ids = options.delete(:skip_default_ids)
19
+ @allow_method_names_outside_object = options.delete(:allow_method_names_outside_object)
20
+ @options = options
21
+
22
+ if Regexp.last_match
23
+ @generate_indexed_names = true
24
+ @auto_index = retrieve_autoindex(Regexp.last_match.pre_match)
25
+ else
26
+ @generate_indexed_names = false
27
+ @auto_index = nil
28
+ end
29
+ end
30
+
31
+ # This is what child classes implement.
32
+ def render
33
+ raise NotImplementedError, "Subclasses must implement a render method"
34
+ end
35
+
36
+ private
37
+ def value
38
+ if @allow_method_names_outside_object
39
+ object.public_send @method_name if object && object.respond_to?(@method_name)
40
+ else
41
+ object.public_send @method_name if object
42
+ end
43
+ end
44
+
45
+ def value_before_type_cast
46
+ unless object.nil?
47
+ method_before_type_cast = @method_name + "_before_type_cast"
48
+
49
+ if value_came_from_user? && object.respond_to?(method_before_type_cast)
50
+ object.public_send(method_before_type_cast)
51
+ else
52
+ value
53
+ end
54
+ end
55
+ end
56
+
57
+ def value_came_from_user?
58
+ method_name = "#{@method_name}_came_from_user?"
59
+ !object.respond_to?(method_name) || object.public_send(method_name)
60
+ end
61
+
62
+ def retrieve_object(object)
63
+ if object
64
+ object
65
+ elsif @template_object.instance_variable_defined?("@#{@object_name}")
66
+ @template_object.instance_variable_get("@#{@object_name}")
67
+ end
68
+ rescue NameError
69
+ # As @object_name may contain the nested syntax (item[subobject]) we need to fallback to nil.
70
+ nil
71
+ end
72
+
73
+ def retrieve_autoindex(pre_match)
74
+ object = self.object || @template_object.instance_variable_get("@#{pre_match}")
75
+ if object && object.respond_to?(:to_param)
76
+ object.to_param
77
+ else
78
+ raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}"
79
+ end
80
+ end
81
+
82
+ def add_default_name_and_id_for_value(tag_value, options)
83
+ if tag_value.nil?
84
+ add_default_name_and_id(options)
85
+ else
86
+ specified_id = options["id"]
87
+ add_default_name_and_id(options)
88
+
89
+ if specified_id.blank? && options["id"].present?
90
+ options["id"] += "_#{sanitized_value(tag_value)}"
91
+ end
92
+ end
93
+ end
94
+
95
+ def add_default_name_and_id(options)
96
+ index = name_and_id_index(options)
97
+ options["name"] = options.fetch("name") { tag_name(options["multiple"], index) }
98
+
99
+ if generate_ids?
100
+ options["id"] = options.fetch("id") { tag_id(index) }
101
+ if namespace = options.delete("namespace")
102
+ options["id"] = options["id"] ? "#{namespace}_#{options['id']}" : namespace
103
+ end
104
+ end
105
+ end
106
+
107
+ def tag_name(multiple = false, index = nil)
108
+ # a little duplication to construct less strings
109
+ case
110
+ when @object_name.empty?
111
+ "#{sanitized_method_name}#{multiple ? "[]" : ""}"
112
+ when index
113
+ "#{@object_name}[#{index}][#{sanitized_method_name}]#{multiple ? "[]" : ""}"
114
+ else
115
+ "#{@object_name}[#{sanitized_method_name}]#{multiple ? "[]" : ""}"
116
+ end
117
+ end
118
+
119
+ def tag_id(index = nil)
120
+ # a little duplication to construct less strings
121
+ case
122
+ when @object_name.empty?
123
+ sanitized_method_name.dup
124
+ when index
125
+ "#{sanitized_object_name}_#{index}_#{sanitized_method_name}"
126
+ else
127
+ "#{sanitized_object_name}_#{sanitized_method_name}"
128
+ end
129
+ end
130
+
131
+ def sanitized_object_name
132
+ @sanitized_object_name ||= @object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
133
+ end
134
+
135
+ def sanitized_method_name
136
+ @sanitized_method_name ||= @method_name.sub(/\?$/, "")
137
+ end
138
+
139
+ def sanitized_value(value)
140
+ value.to_s.gsub(/[\s\.]/, "_").gsub(/[^-[[:word:]]]/, "").downcase
141
+ end
142
+
143
+ def select_content_tag(option_tags, options, html_options)
144
+ html_options = html_options.stringify_keys
145
+ add_default_name_and_id(html_options)
146
+
147
+ if placeholder_required?(html_options)
148
+ raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
149
+ options[:include_blank] ||= true unless options[:prompt]
150
+ end
151
+
152
+ value = options.fetch(:selected) { value() }
153
+ select = content_tag("select", add_options(option_tags, options, value), html_options)
154
+
155
+ if html_options["multiple"] && options.fetch(:include_hidden, true)
156
+ tag("input", disabled: html_options["disabled"], name: html_options["name"], type: "hidden", value: "") + select
157
+ else
158
+ select
159
+ end
160
+ end
161
+
162
+ def placeholder_required?(html_options)
163
+ # See https://html.spec.whatwg.org/multipage/forms.html#attr-select-required
164
+ html_options["required"] && !html_options["multiple"] && html_options.fetch("size", 1).to_i == 1
165
+ end
166
+
167
+ def add_options(option_tags, options, value = nil)
168
+ if options[:include_blank]
169
+ option_tags = tag_builder.content_tag_string("option", options[:include_blank].kind_of?(String) ? options[:include_blank] : nil, value: "") + "\n" + option_tags
170
+ end
171
+ if value.blank? && options[:prompt]
172
+ tag_options = { value: "" }.tap do |prompt_opts|
173
+ prompt_opts[:disabled] = true if options[:disabled] == ""
174
+ prompt_opts[:selected] = true if options[:selected] == ""
175
+ end
176
+ option_tags = tag_builder.content_tag_string("option", prompt_text(options[:prompt]), tag_options) + "\n" + option_tags
177
+ end
178
+ option_tags
179
+ end
180
+
181
+ def name_and_id_index(options)
182
+ if options.key?("index")
183
+ options.delete("index") || ""
184
+ elsif @generate_indexed_names
185
+ @auto_index || ""
186
+ end
187
+ end
188
+
189
+ def generate_ids?
190
+ !@skip_default_ids
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "action_view/helpers/tags/checkable"
4
+
5
+ module ActionView
6
+ module Helpers
7
+ module Tags # :nodoc:
8
+ class CheckBox < Base #:nodoc:
9
+ include Checkable
10
+
11
+ def initialize(object_name, method_name, template_object, checked_value, unchecked_value, options)
12
+ @checked_value = checked_value
13
+ @unchecked_value = unchecked_value
14
+ super(object_name, method_name, template_object, options)
15
+ end
16
+
17
+ def render
18
+ options = @options.stringify_keys
19
+ options["type"] = "checkbox"
20
+ options["value"] = @checked_value
21
+ options["checked"] = "checked" if input_checked?(options)
22
+
23
+ if options["multiple"]
24
+ add_default_name_and_id_for_value(@checked_value, options)
25
+ options.delete("multiple")
26
+ else
27
+ add_default_name_and_id(options)
28
+ end
29
+
30
+ include_hidden = options.delete("include_hidden") { true }
31
+ checkbox = tag("input", options)
32
+
33
+ if include_hidden
34
+ hidden = hidden_field_for_checkbox(options)
35
+ hidden + checkbox
36
+ else
37
+ checkbox
38
+ end
39
+ end
40
+
41
+ private
42
+ def checked?(value)
43
+ case value
44
+ when TrueClass, FalseClass
45
+ value == !!@checked_value
46
+ when NilClass
47
+ false
48
+ when String
49
+ value == @checked_value
50
+ else
51
+ if value.respond_to?(:include?)
52
+ value.include?(@checked_value)
53
+ else
54
+ value.to_i == @checked_value.to_i
55
+ end
56
+ end
57
+ end
58
+
59
+ def hidden_field_for_checkbox(options)
60
+ @unchecked_value ? tag("input", options.slice("name", "disabled", "form").merge!("type" => "hidden", "value" => @unchecked_value)) : "".html_safe
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end