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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5008fffbdaeea146d66dce529f832032f7275362
4
- data.tar.gz: 8c548e93a7162d22d85cc6d12cead6d1fd40e8b1
3
+ metadata.gz: 8d8242e1d0a285d314bbd8a6579e3a0c94da705d
4
+ data.tar.gz: 691b775513a957ab9e67c599743f3679d257b3da
5
5
  SHA512:
6
- metadata.gz: e2ee2471f739789834bb7a6a2426f089e50253f0921ebfbe7c0862d0cce9f6246895584fe3a71a0c5b8f2c5e0ada79373f5bc6c65c39d2c5afe795b8ec2113de
7
- data.tar.gz: c84d6391eae56b6688884253f99a7b2902e979baf5ea643dba61d5c0e89c1b3aae472d19efb742e70a66e1855adea7d8b080d97061264b64d630bb36ca4ba14d
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, options = {}, &block)
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, @template = object, template
18
+ @object = object
19
+ @template = template
18
20
  end
19
21
 
20
- def panel(title, &block)
21
- content_tag(:div, class: "panel panel-default") do
22
- concat(panel_heading(title))
23
- concat(panel_body(&block))
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 panel_heading(title)
28
- content_tag(:div, class: "panel-heading") do
29
- content_tag(:h3, title.to_s.titleize, class: "panel-title")
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 panel_body(&block)
34
- content_tag(:div, class: "panel-body") do
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
@@ -1,3 +1,3 @@
1
1
  module PanelsFor
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/panels_for.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require "panels_for/version"
2
2
  require "panels_for/engine"
3
+ require "font-awesome-rails"