effective_bootstrap 1.14.17 → 1.15.1

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: af2549f2ba32f64fc74a0ae241dd5ff3e5f426f36f5af01680de3f14adcd6c3b
4
- data.tar.gz: ec2bebf9c1c4c7f6b94e9f655960e186908d01f4b5f2d35de995c299f52c5d5d
3
+ metadata.gz: 5cfaf018bf0d9801faa459d991cc6831c09878bf7d7395c8eceeb247c2b8efb8
4
+ data.tar.gz: 7441f4d44bf47958d9a1bb85466750f2a55031436af91c34a53f9dc9a7328898
5
5
  SHA512:
6
- metadata.gz: '09b9c54ade1926de6b3643665d375ef2490c0b2bee23415b719f98fae8aed04d414bc499f569d95c3aade9f6639c5f7783f6ffba619afa4136f8cde2ec0e45a9'
7
- data.tar.gz: d2b3953a4470819ad35324b503b29046635c84ba736f9d11808ef172ccc2f8791366510f411050a3e03403f6d1252e88de2e4c53f6a24e7bac1f2b16bfc8863f
6
+ metadata.gz: acec024092be3e7a9ad139f88cac0651971bc3cde9e49857080b60cbfa10b3cd959be6e98002b8d103dea75b21382b4c67e644b9aadcfac0bacd078e55655dba
7
+ data.tar.gz: 2c0107069432b98107335a6827239e8b3ec61fc53ff3ae0d8f0e4ece573cc2e9af53bcc360d7281231466c6e7db82244abf567f54beceb45220521ab592fab27
@@ -27,17 +27,25 @@ module Effective
27
27
  # This runs the form partial over this table builder
28
28
  capture(&block) if block_given?
29
29
 
30
- # Build from the resource if we didn't do anything in the block
31
- build_resource_rows if rows.blank? && !block_given?
32
-
30
+ # Consider content
33
31
  only = Array(options[:only])
34
32
  except = Array(options[:except])
33
+ additionally = Array(options[:additionally])
35
34
  filtered = filter_parameters
36
35
 
36
+ # Rows are created when we use the block syntax and call a f.text_field or other f.form_field
37
+ # Using = f.content_for does not create a row.
38
+ # So rows wille be blank when using the default syntax
39
+ # And rows will be present when we render a form, or any form fields
40
+ build_resource_rows(only: only, except: except) if rows.blank?
41
+
42
+ # This gives us a second run through the rows, if you pass additionally
43
+ build_resource_rows(only: additionally) if additionally.present?
44
+
45
+ # Use f.content_for :name to override the content
37
46
  content = rows.merge(content_fors)
38
47
 
39
- content = content.slice(*only) if only.present?
40
- content = content.except(*except) if except.present?
48
+ # Filter out some hardcoded ones
41
49
  content = content.except(*filtered) if filtered.present?
42
50
 
43
51
  content_tag(:table, class: options.fetch(:class, 'table table-sm table-striped table-hover effective-table-summary')) do
@@ -54,8 +62,11 @@ module Effective
54
62
  end
55
63
  end
56
64
 
57
- def build_resource_rows
65
+ def build_resource_rows(only: nil, except: nil)
58
66
  Effective::Resource.new(object).resource_attributes.each do |name, options|
67
+ next if only.present? && only.exclude?(name)
68
+ next if except.present? && except.include?(name)
69
+
59
70
  case options.first
60
71
  when :belongs_to
61
72
  belongs_to(name)
@@ -64,7 +75,13 @@ module Effective
64
75
  when :boolean
65
76
  boolean_row(name)
66
77
  when :integer
67
- ['price', 'discount', '_fee'].any? { |p| name.to_s.include?(p) } ? price_field(name) : text_field(name)
78
+ if ['price', 'discount', '_fee'].any? { |p| name.to_s.include?(p) }
79
+ price_field(name)
80
+ elsif ['_percent'].any? { |p| name.to_s.include?(p) }
81
+ percent_field(name)
82
+ else
83
+ text_field(name)
84
+ end
68
85
  when :string
69
86
  name.to_s.include?('email') ? email_field(name) : text_field(name)
70
87
  when :text
@@ -100,6 +117,10 @@ module Effective
100
117
  rows[name] = TableRow.new(name, options, builder: self).to_html
101
118
  end
102
119
 
120
+ def article_editor(name, options = {})
121
+ rows[name] = TableRows::ArticleEditor.new(name, options, builder: self).to_html
122
+ end
123
+
103
124
  def boolean_row(name, options = {})
104
125
  rows[name] = TableRows::Boolean.new(name, options, builder: self).to_html
105
126
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Effective
4
+ module TableRows
5
+ class ArticleEditor < Effective::TableRow
6
+
7
+ def content
8
+ return unless value.present?
9
+
10
+ if value.start_with?('<') && value.end_with?('>')
11
+ value.html_safe
12
+ else
13
+ template.simple_format(value)
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -13,11 +13,15 @@ module Effective
13
13
  values = Array(value) - [nil, '']
14
14
 
15
15
  if values.length > 1
16
- values.map { |v| content_tag(:div, v) }.join.html_safe
16
+ values.map { |v| content_tag(:div, item_content(v)) }.join.html_safe
17
17
  elsif values.length == 1
18
- values.first
18
+ item_content(values.first)
19
19
  end
20
+ end
20
21
 
22
+ def item_content(value)
23
+ item = @collection.find { |k, v| (k && k == value) || (v && v == value) || k.try(:id) == value }
24
+ (item || value).to_s
21
25
  end
22
26
 
23
27
  end
@@ -5,7 +5,16 @@ module Effective
5
5
  class TextArea < Effective::TableRow
6
6
 
7
7
  def content
8
- template.simple_format(value) if value.kind_of?(String)
8
+ return unless value.present?
9
+
10
+ # Might be an Array or Hash. Serialized something.
11
+ return value.to_s unless value.kind_of?(String)
12
+
13
+ if value.start_with?('<') && value.end_with?('>')
14
+ value.html_safe
15
+ else
16
+ template.simple_format(value)
17
+ end
9
18
  end
10
19
 
11
20
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveBootstrap
2
- VERSION = '1.14.17'.freeze
2
+ VERSION = '1.15.1'.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.17
4
+ version: 1.15.1
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-09-01 00:00:00.000000000 Z
11
+ date: 2023-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -696,6 +696,7 @@ files:
696
696
  - app/models/effective/form_logics/show_if_any.rb
697
697
  - app/models/effective/table_builder.rb
698
698
  - app/models/effective/table_row.rb
699
+ - app/models/effective/table_rows/article_editor.rb
699
700
  - app/models/effective/table_rows/belongs_to.rb
700
701
  - app/models/effective/table_rows/boolean.rb
701
702
  - app/models/effective/table_rows/collection.rb