effective_bootstrap 1.14.12 → 1.14.14

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
  SHA256:
3
- metadata.gz: da449090f0915cf6fbf42994401f49056bcc5fe1e1f6e45130b885f138cee53d
4
- data.tar.gz: 5a8b92d846eb7ab5d6c1cfe644cf38cde4bda42600f87d18ee4dff7d5dbe9a8e
3
+ metadata.gz: d24661035aefda568e36bd05da600c648106f9d8848cf451fb05507ae6c8d34b
4
+ data.tar.gz: 7b7255fad5bbebe43bd5c7e751c26444fa32e2eee36d0a73df174d8a6c61b578
5
5
  SHA512:
6
- metadata.gz: af6d95df0e83cb5dbb65a11f3666be5ef22a9f91797455e53343ceaecbdb4a2eb87ac9a2bcbdadbac9a20427bd55de0778829ca92859a02e74d7e2b905629dbf
7
- data.tar.gz: 738864c3b53d675f58eef22f2ca32c72df0c628e59a25da0087c2f24ad4f62a95b51038ebf75e8a61a00bf7e3c740364fafafc9a6ad38a41c3d2ef86652063ed
6
+ metadata.gz: f67ec2cc997cd11a97c447c851eaee940e93bd0702d9218d8cc6f8c5af5c3649326cd3c3abfc9877bdf0ca04ffae7bb367c7c79e124db848bf72e9e5ebba6491
7
+ data.tar.gz: 7aa8297e0a5c2a7fdbea857301abdd05641f4b96f047a6fa2f2bee8be40f6d66196c1ef917695e048c9936333bea8aec802e89777c2b73a5b718d573671c3f9d
data/README.md CHANGED
@@ -697,6 +697,23 @@ The `f.save` is purely a input submit button.
697
697
  = f.save 'Save 2'
698
698
  ```
699
699
 
700
+ ## Internationalization
701
+
702
+ The form builder will use labels and hints based on your current localization, if present
703
+
704
+ To use these, just assign the activemodel attributes values to your strings
705
+
706
+ ```
707
+ en:
708
+ activerecord:
709
+ models:
710
+ thing: 'Thing'
711
+ attributes:
712
+ thing:
713
+ title: 'Good Title'
714
+ title_hint: 'please make this title really good'
715
+ ```
716
+
700
717
  ## Table Builder
701
718
 
702
719
  Use `effective_table_with(resource)` to intelligently output a table of attributes for a resource.
@@ -766,6 +783,7 @@ You can specify `only:` and `except:` and use `f.content_for` to override a row
766
783
 
767
784
  All values flow through to i18n and can be overriden, same as the form labels, in the locale .yml file.
768
785
 
786
+
769
787
  ## License
770
788
 
771
789
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -20,5 +20,10 @@ $(document).on 'direct-upload:end', (event) ->
20
20
  # Rails UJS fix
21
21
  $obj.closest('form').find('[type=submit][data-confirm]').data('confirmed', true)
22
22
 
23
+ # Remove any empty [] inputs after upload
24
+ $obj.closest('.form-group').find('input').each (i, input) ->
25
+ $input = $(input)
26
+ $input.remove() unless $input.val()
27
+
23
28
  $(document).on 'change', "input[type='file'][data-click-submit]", (event) ->
24
29
  $(event.currentTarget).closest('form').find('button[type=submit],input[type=submit]').first().click()
@@ -140,20 +140,7 @@ module Effective
140
140
  return BLANK if options[:label] == false
141
141
  return BLANK if name.kind_of?(NilClass)
142
142
 
143
- text = options[:label].delete(:text)
144
- name_to_s = name.to_s
145
-
146
- text ||= (
147
- if object && name_to_s.ends_with?('_id')
148
- object.class.human_attribute_name(name_to_s.chomp('_id'))
149
- elsif object && name_to_s.ends_with?('_ids')
150
- object.class.human_attribute_name(name_to_s.chomp('_ids').pluralize)
151
- elsif object
152
- object.class.human_attribute_name(name)
153
- else
154
- BLANK
155
- end
156
- )
143
+ text = options[:label].delete(:text) || build_human_label()
157
144
 
158
145
  if options[:input][:id]
159
146
  options[:label][:for] = options[:input][:id]
@@ -162,19 +149,56 @@ module Effective
162
149
  @builder.label(name, text.html_safe, options[:label])
163
150
  end
164
151
 
152
+ def build_human_label
153
+ name = self.name.to_s
154
+
155
+ label = if object && name.ends_with?('_id')
156
+ object.class.human_attribute_name(name.chomp('_id'))
157
+ elsif object && name.ends_with?('_ids')
158
+ object.class.human_attribute_name(name.chomp('_ids').pluralize)
159
+ elsif object
160
+ object.class.human_attribute_name(name)
161
+ else
162
+ BLANK
163
+ end
164
+
165
+ label
166
+ end
167
+
165
168
  def build_input(&block)
166
169
  capture(&block)
167
170
  end
168
171
 
169
172
  def build_hint
170
- return BLANK unless options[:hint] && options[:hint][:text]
173
+ return BLANK if options[:label] == false
174
+ return BLANK if name.kind_of?(NilClass)
171
175
 
172
176
  tag = options[:hint].delete(:tag)
173
- text = options[:hint].delete(:text)
177
+ text = options[:hint].delete(:text) || build_human_hint()
178
+ return BLANK unless text.present?
174
179
 
175
180
  content_tag(tag, text.html_safe, options[:hint])
176
181
  end
177
182
 
183
+ def build_human_hint
184
+ name = self.name.to_s
185
+
186
+ key = if object && name.ends_with?('_id')
187
+ "activerecord.attributes.#{object.model_name.i18n_key}.#{name.chomp('_id')}_hint"
188
+ elsif object && name.ends_with?('_ids')
189
+ "activerecord.attributes.#{object.model_name.i18n_key}.#{name.chomp('_ids').pluralize}_hint"
190
+ elsif object
191
+ "activerecord.attributes.#{object.model_name.i18n_key}.#{name}_hint"
192
+ end
193
+
194
+ return nil if key.blank?
195
+
196
+ hint = ::I18n.t(key)
197
+ return nil if hint.include?(key) # missing translation
198
+
199
+ hint
200
+ end
201
+
178
202
  def build_feedback
179
203
  return BLANK if options[:feedback] == false
180
204
 
@@ -35,6 +35,7 @@ module Effective
35
35
  filtered = filter_parameters
36
36
 
37
37
  content = rows.merge(content_fors)
38
+
38
39
  content = content.slice(*only) if only.present?
39
40
  content = content.except(*except) if except.present?
40
41
  content = content.except(*filtered) if filtered.present?
@@ -168,11 +169,11 @@ module Effective
168
169
  rows[name] = TableRows::PriceField.new(name, options, builder: self).to_html
169
170
  end
170
171
 
171
- def save(name, options = {})
172
+ def save(name = nil, options = {})
172
173
  # Nothing to do
173
174
  end
174
175
 
175
- def submit(name, options = {}, &block)
176
+ def submit(name = nil, options = {}, &block)
176
177
  # Nothing to do
177
178
  end
178
179
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '1.14.12'.freeze
2
+ VERSION = '1.14.14'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_bootstrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.12
4
+ version: 1.14.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-04 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails