effective_resources 0.3.10 → 0.3.11
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c25e36357edcadd3180eca0a181c8b3c4acf4f21
|
4
|
+
data.tar.gz: f70d3b19608cc354782dcb756b960301d40d12aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8cd4177e5d66d6421ce3cd354bc4164e3c18599cc15af3ac47d9c4d2cda7864af4f31ce61c8184252d99543e59e520cd80ca149cd1ca843959248ad2fda186b
|
7
|
+
data.tar.gz: dcb5869b6d3a5a6f4b93a401435ded35287859ba80f9e1aec61d905c4194db65d6505b44cfd6363cb8bdf87dd96425ca876fd396326ebc1e4f4c2db5e1ca34f8
|
@@ -71,5 +71,42 @@ module EffectiveResourcesHelper
|
|
71
71
|
alias_method :bootstrap_icon_to, :glyphicon_to
|
72
72
|
alias_method :glyph_icon_to, :glyphicon_to
|
73
73
|
|
74
|
+
### Tableize attributes
|
75
|
+
|
76
|
+
# This is used by effective_orders, effective_logging, effective_trash and effective_mergery
|
77
|
+
def tableize_hash(obj, table: 'table', th: true, sub_table: 'table', sub_th: true, flatten: true)
|
78
|
+
case obj
|
79
|
+
when Hash
|
80
|
+
if flatten && obj[:attributes].kind_of?(Hash)
|
81
|
+
obj = obj[:attributes].merge(obj.except(:attributes))
|
82
|
+
end
|
83
|
+
|
84
|
+
content_tag(:table, class: table.presence) do
|
85
|
+
content_tag(:tbody) do
|
86
|
+
obj.map do |key, value|
|
87
|
+
content_tag(:tr) do
|
88
|
+
content_tag((th == true ? :th : :td), key) +
|
89
|
+
content_tag(:td) { tableize_hash(value, table: sub_table, th: sub_th, sub_table: sub_table, sub_th: sub_th, flatten: flatten) }
|
90
|
+
end
|
91
|
+
end.join.html_safe
|
92
|
+
end
|
93
|
+
end
|
94
|
+
when Array
|
95
|
+
obj.map { |value| tableize_hash(value, table: sub_table, th: sub_th, sub_table: sub_table, sub_th: sub_th, flatten: flatten) }.join('<br>')
|
96
|
+
when Symbol
|
97
|
+
":#{obj}"
|
98
|
+
when NilClass
|
99
|
+
'-'
|
100
|
+
else
|
101
|
+
obj.to_s.presence || '""'
|
102
|
+
end.html_safe
|
103
|
+
end
|
104
|
+
|
105
|
+
def format_resource_value(value)
|
106
|
+
@format_resource_tags ||= ActionView::Base.sanitized_allowed_tags.to_a + ['table', 'thead', 'tbody', 'tfoot', 'tr', 'td', 'th']
|
107
|
+
@format_resource_atts ||= ActionView::Base.sanitized_allowed_attributes.to_a + ['colspan', 'rowspan']
|
108
|
+
|
109
|
+
simple_format(sanitize(value.to_s, tags: @format_resource_tags, attributes: @format_resource_atts), {}, sanitize: false)
|
110
|
+
end
|
74
111
|
|
75
112
|
end
|
@@ -28,7 +28,7 @@ module Effective
|
|
28
28
|
|
29
29
|
def nested_resources
|
30
30
|
return [] unless klass.respond_to?(:reflect_on_all_associations)
|
31
|
-
@nested_resources ||= klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave]
|
31
|
+
@nested_resources ||= klass.reflect_on_all_associations(:has_many).select { |ass| ass.options[:autosave] }
|
32
32
|
end
|
33
33
|
|
34
34
|
def associated(name)
|
@@ -19,12 +19,8 @@ module Effective
|
|
19
19
|
attributes[association.name] = instance.send(association.name).to_s
|
20
20
|
end
|
21
21
|
|
22
|
-
has_ones.each do |association|
|
23
|
-
attributes[association.name] = instance.send(association.name).to_s
|
24
|
-
end
|
25
|
-
|
26
22
|
nested_resources.each do |association|
|
27
|
-
attributes[association.name]
|
23
|
+
attributes[association.name] ||= {}
|
28
24
|
|
29
25
|
Array(instance.send(association.name)).each_with_index do |child, index|
|
30
26
|
resource = Effective::Resource.new(child)
|
@@ -32,6 +28,18 @@ module Effective
|
|
32
28
|
end
|
33
29
|
end
|
34
30
|
|
31
|
+
has_ones.each do |association|
|
32
|
+
attributes[association.name] = instance.send(association.name).to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
has_manys.each do |association|
|
36
|
+
attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
|
37
|
+
end
|
38
|
+
|
39
|
+
has_and_belongs_to_manys.each do |association|
|
40
|
+
attributes[association.name] = instance.send(association.name).map { |obj| obj.to_s }
|
41
|
+
end
|
42
|
+
|
35
43
|
attributes.delete_if { |_, value| value.blank? }
|
36
44
|
end
|
37
45
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.11
|
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: 2017-
|
11
|
+
date: 2017-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|