effective_bootstrap 1.14.12 → 1.14.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da449090f0915cf6fbf42994401f49056bcc5fe1e1f6e45130b885f138cee53d
4
- data.tar.gz: 5a8b92d846eb7ab5d6c1cfe644cf38cde4bda42600f87d18ee4dff7d5dbe9a8e
3
+ metadata.gz: c79b3e0f8e491e05ac28f6fe0630f669f3ced789b5137ed76fac5ba9e5bc2149
4
+ data.tar.gz: f50ff44c62e6b68098f5210361933ff1eb0fcb0c2d3c67c4cdd5296cb6b8fe37
5
5
  SHA512:
6
- metadata.gz: af6d95df0e83cb5dbb65a11f3666be5ef22a9f91797455e53343ceaecbdb4a2eb87ac9a2bcbdadbac9a20427bd55de0778829ca92859a02e74d7e2b905629dbf
7
- data.tar.gz: 738864c3b53d675f58eef22f2ca32c72df0c628e59a25da0087c2f24ad4f62a95b51038ebf75e8a61a00bf7e3c740364fafafc9a6ad38a41c3d2ef86652063ed
6
+ metadata.gz: 52236956016cb32d8d35b3a4a22a88a5255696bc19a0f4b08e7e789fe3726e7fd84062b7d132e55a05b86ab30bf7bbeecc14f411113305a3543a2699d7a95a59
7
+ data.tar.gz: d116da97f759170fe2b718e429d1125ebfa339acb8863a4afd49a001746edd22e2c3bad37d5126154222382e4a16bb39d028c9d88410f70b89d8bf238f867d6c
data/README.md CHANGED
@@ -697,6 +697,21 @@ 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
+ en:
707
+ activerecord:
708
+ models:
709
+ thing: 'Thing'
710
+ attributes:
711
+ thing:
712
+ title: 'Good Title'
713
+ title_hint: 'please make this title really good'
714
+
700
715
  ## Table Builder
701
716
 
702
717
  Use `effective_table_with(resource)` to intelligently output a table of attributes for a resource.
@@ -766,6 +781,7 @@ You can specify `only:` and `except:` and use `f.content_for` to override a row
766
781
 
767
782
  All values flow through to i18n and can be overriden, same as the form labels, in the locale .yml file.
768
783
 
784
+
769
785
  ## License
770
786
 
771
787
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
@@ -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.13'.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.13
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-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails