panels_for 0.1.0 → 0.2.0
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 +4 -4
- data/app/helpers/panels_for/rails/panels_for_helper.rb +86 -11
- data/lib/panels_for/version.rb +1 -1
- data/lib/panels_for.rb +1 -0
- data/test/dummy/log/test.log +1308 -0
- data/test/panels_for_helper_test.rb +22 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d8242e1d0a285d314bbd8a6579e3a0c94da705d
|
4
|
+
data.tar.gz: 691b775513a957ab9e67c599743f3679d257b3da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cf99f3ad078b83d299f0d28b64ee6b4ebde677013a8521902102c1dca8ba39948c9d6be47428807ee7002b2bd9a88dcf780eb52becd90e29c28d2fa938a6ccc
|
7
|
+
data.tar.gz: 273f1050f5d792ef10c482a21232eeac803d2744d50dee5495eec83aecaa8cbaef4e49e6b2cfcf9f01fa090f43fb3bcf81eee9bcb426cd194f68cac33971d232
|
@@ -2,7 +2,7 @@ module PanelsFor
|
|
2
2
|
module Rails
|
3
3
|
module PanelsForHelper
|
4
4
|
|
5
|
-
def panels_for(object,
|
5
|
+
def panels_for(object, &block)
|
6
6
|
capture PanelBuilder.new(object, self), &block
|
7
7
|
end
|
8
8
|
|
@@ -10,32 +10,107 @@ module PanelsFor
|
|
10
10
|
|
11
11
|
class PanelBuilder
|
12
12
|
include ActionView::Helpers
|
13
|
+
include FontAwesome::Rails::IconHelper
|
13
14
|
|
14
15
|
attr_accessor :object, :template, :output_buffer
|
15
16
|
|
16
17
|
def initialize(object, template)
|
17
|
-
@object
|
18
|
+
@object = object
|
19
|
+
@template = template
|
18
20
|
end
|
19
21
|
|
20
|
-
def panel(title, &block)
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
def panel(title, options = {}, &block)
|
23
|
+
content = panel_default(title, options, &block)
|
24
|
+
options[:collapse] ? panel_group(title, content) : content
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def panel_default(title, options = {}, &block)
|
30
|
+
content_tag(:div, class: 'panel panel-default') do
|
31
|
+
concat(panel_heading(title, options))
|
32
|
+
concat(panel_body(title, options, &block))
|
24
33
|
end
|
25
34
|
end
|
26
35
|
|
27
|
-
def
|
28
|
-
content_tag(
|
29
|
-
|
36
|
+
def panel_group(title, content)
|
37
|
+
content_tag(
|
38
|
+
:div,
|
39
|
+
content,
|
40
|
+
class:
|
41
|
+
'panel-group',
|
42
|
+
id: "#{title.to_s.underscore}_accordian",
|
43
|
+
role: 'tablist',
|
44
|
+
aria: { multiselectable: 'true' }
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
def panel_heading(title, options = {})
|
49
|
+
content = prepare_content(title, options)
|
50
|
+
expanded = options[:expanded] ? 'true' : 'false'
|
51
|
+
|
52
|
+
if options[:collapse]
|
53
|
+
content = link_to(
|
54
|
+
content, "##{collapse_id(title)}",
|
55
|
+
role: 'button',
|
56
|
+
data: {
|
57
|
+
toggle: 'collapse',
|
58
|
+
parent: "##{title.to_s.underscore}_accordian"
|
59
|
+
},
|
60
|
+
aria: { expanded: expanded, controls: collapse_id(title) }
|
61
|
+
)
|
62
|
+
content_tag(:div, panel_title(content),
|
63
|
+
class: 'panel-heading',
|
64
|
+
role: 'tab',
|
65
|
+
id: heading_id(title))
|
66
|
+
else
|
67
|
+
content_tag(:div, class: 'panel-heading') do
|
68
|
+
panel_title(content)
|
69
|
+
end
|
30
70
|
end
|
31
71
|
end
|
32
72
|
|
33
|
-
def
|
34
|
-
content_tag(:
|
73
|
+
def panel_title(content)
|
74
|
+
content_tag(:h4, content, class: 'panel-title')
|
75
|
+
end
|
76
|
+
|
77
|
+
def panel_body(title, options = {}, &block)
|
78
|
+
content = content_tag(:div, class: 'panel-body') do
|
35
79
|
template.capture(&block)
|
36
80
|
end
|
81
|
+
|
82
|
+
if options[:collapse]
|
83
|
+
panel_body_collapse(title, content, options)
|
84
|
+
else
|
85
|
+
content
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def panel_body_collapse(title, content, options)
|
90
|
+
classes = 'panel-collapse collapse'
|
91
|
+
classes << ' in' unless options[:collapsed]
|
92
|
+
content_tag(
|
93
|
+
:div,
|
94
|
+
content,
|
95
|
+
id: "collapse_#{title.to_s.underscore}",
|
96
|
+
class: classes,
|
97
|
+
role: 'tabpanel',
|
98
|
+
aria: { labelledby: heading_id(title) }
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def prepare_content(title, options)
|
103
|
+
content = title.to_s.titleize
|
104
|
+
options[:icon] ? fa_icon(options[:icon], text: content) : content
|
105
|
+
end
|
106
|
+
|
107
|
+
def heading_id(title)
|
108
|
+
"heading_#{title.to_s.underscore}"
|
37
109
|
end
|
38
110
|
|
111
|
+
def collapse_id(title)
|
112
|
+
"collapse_#{title.to_s.underscore}"
|
113
|
+
end
|
39
114
|
end
|
40
115
|
end
|
41
116
|
end
|
data/lib/panels_for/version.rb
CHANGED
data/lib/panels_for.rb
CHANGED