effective_bootstrap 1.14.11 → 1.14.13

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: c1c4ea60a0fdc9507852b607ec9809e8fb28490695f05df02ef4a8c11a1073ad
4
- data.tar.gz: ce5db2b16eb76d873d0cf0149c9e1eef9099f24a93c9c6fce89f4439013b3a4f
3
+ metadata.gz: c79b3e0f8e491e05ac28f6fe0630f669f3ced789b5137ed76fac5ba9e5bc2149
4
+ data.tar.gz: f50ff44c62e6b68098f5210361933ff1eb0fcb0c2d3c67c4cdd5296cb6b8fe37
5
5
  SHA512:
6
- metadata.gz: 16cd1d8a558e7af223b3084fb281051c3bf54d59adbc26e3b357d22e36aaefd5f7c8674fde3e84a9b0a2907025d613997e580e0d8f8da61707bd714b02881daa
7
- data.tar.gz: b4cbd3b1aed8ef57810de7d64ef9997c7d80ab5a759ebb326ddcda13415f1dce247944bbe6101db105ccc534f2fe5eb98839afe63b096d96530f4ac2aae85f8d
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?
@@ -119,6 +120,14 @@ module Effective
119
120
  rows[name] = TableRows::BelongsTo.new(name, options, builder: self).to_html
120
121
  end
121
122
 
123
+ def date_field(name, options = {})
124
+ rows[name] = TableRows::DateField.new(name, options, builder: self).to_html
125
+ end
126
+
127
+ def datetime_field(name, options = {})
128
+ rows[name] = TableRows::DatetimeField.new(name, options, builder: self).to_html
129
+ end
130
+
122
131
  def email_field(name, options = {})
123
132
  rows[name] = TableRows::EmailField.new(name, options, builder: self).to_html
124
133
  end
@@ -152,15 +161,19 @@ module Effective
152
161
  rows[name] = TableRows::PercentField.new(name, options, builder: self).to_html
153
162
  end
154
163
 
164
+ def tel_field(name, options = {})
165
+ rows[name] = TableRows::PhoneField.new(name, options, builder: self).to_html
166
+ end
167
+
155
168
  def price_field(name, options = {})
156
169
  rows[name] = TableRows::PriceField.new(name, options, builder: self).to_html
157
170
  end
158
171
 
159
- def save(name, options = {})
172
+ def save(name = nil, options = {})
160
173
  # Nothing to do
161
174
  end
162
175
 
163
- def submit(name, options = {}, &block)
176
+ def submit(name = nil, options = {}, &block)
164
177
  # Nothing to do
165
178
  end
166
179
 
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Effective
4
+ module TableRows
5
+ class DateField < Effective::TableRow
6
+
7
+ def content
8
+ nice_date(value)
9
+ end
10
+
11
+ def nice_date(value)
12
+ return unless value.respond_to?(:strftime)
13
+
14
+ label = value.strftime("%b %-d, %Y")
15
+ full = value.strftime("%A %b %-d, %Y %l:%M%P %z")
16
+
17
+ now = Time.zone.now
18
+
19
+ distance = if (now > value)
20
+ template.distance_of_time_in_words(now, value) + ' ago'
21
+ else
22
+ template.distance_of_time_in_words(value, now) + ' from now'
23
+ end
24
+
25
+ content_tag(:span, label, title: full + ' (' + distance + ')')
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Effective
4
+ module TableRows
5
+ class DatetimeField < Effective::TableRow
6
+
7
+ def content
8
+ nice_date_time(value)
9
+ end
10
+
11
+ def nice_date_time(value)
12
+ return unless value.respond_to?(:strftime)
13
+
14
+ label = value.strftime("%b %-d, %Y %l:%M%P")
15
+ full = value.strftime("%A %b %-d, %Y %l:%M%P %z")
16
+
17
+ now = Time.zone.now
18
+
19
+ distance = if (now > value)
20
+ template.distance_of_time_in_words(now, value) + ' ago'
21
+ else
22
+ template.distance_of_time_in_words(value, now) + ' from now'
23
+ end
24
+
25
+ content_tag(:span, label, title: full + ' (' + distance + ')')
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Effective
4
+ module TableRows
5
+ class PhoneField < Effective::TableRow
6
+
7
+ def content
8
+ return unless value.present?
9
+
10
+ digits = value.split('x').first.delete('^0-9')
11
+ link_to(value, "tel:+1#{digits}")
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -5,7 +5,7 @@ module Effective
5
5
  class UrlField < Effective::TableRow
6
6
 
7
7
  def content
8
- template.link_to(value) if value.present?
8
+ template.link_to(value, value, target: '_blank') if value.present?
9
9
  end
10
10
 
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '1.14.11'.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.11
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-07-27 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
@@ -700,10 +700,13 @@ files:
700
700
  - app/models/effective/table_rows/boolean.rb
701
701
  - app/models/effective/table_rows/collection.rb
702
702
  - app/models/effective/table_rows/content_for.rb
703
+ - app/models/effective/table_rows/date_field.rb
704
+ - app/models/effective/table_rows/datetime_field.rb
703
705
  - app/models/effective/table_rows/effective_address.rb
704
706
  - app/models/effective/table_rows/email_field.rb
705
707
  - app/models/effective/table_rows/file_field.rb
706
708
  - app/models/effective/table_rows/percent_field.rb
709
+ - app/models/effective/table_rows/phone_field.rb
707
710
  - app/models/effective/table_rows/price_field.rb
708
711
  - app/models/effective/table_rows/text_area.rb
709
712
  - app/models/effective/table_rows/url_field.rb