Module: PureAdmin::PortletHelper
- Defined in:
- app/helpers/pure_admin/portlet_helper.rb
Overview
Helper methods to assist in building Pure Admin portlets.
Instance Method Summary collapse
-
#portlet(title, options = {}) { ... } ⇒ Object
Renders a “portlet” to the view.
Instance Method Details
#portlet(title, options = {}) { ... } ⇒ Object
Renders a “portlet” to the view.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/helpers/pure_admin/portlet_helper.rb', line 12 def portlet(title, = {}, &block) portlet_html = [:portlet_html] || {} portlet_html[:class] = ['portlet clear-fix', portlet_html[:class]] portlet_html[:data] ||= {} portlet_html[:data][:source] = [:source] unless block_given? heading_html = .delete(:heading_html) || {} heading_html[:class] = merge_html_classes('portlet-heading', heading_html[:class]) body_html = .delete(:body_html) || {} body_html[:class] = merge_html_classes('portlet-body clear-fix', body_html[:class]) if [:icon] icon = content_tag(:i, nil, class: "portlet-heading-icon fa fa-fw fa-#{[:icon].to_s.dasherize}") end # This determines if the portlet can be closed. If it is remote it can be closed. If not, # it is determined by the presence of expand in the options. # e.g. <%= portlet 'A title', expand: true do %>... closable = .key?(:source) || .key?(:expand) portlet_html[:data][:closable] = closable controls_content = ''.html_safe controls = .delete(:controls) if controls.present? if controls.respond_to?(:each) controls.each do |control| controls_content << content_tag(:span, control, class: 'portlet-control-item') end else controls_content << content_tag(:span, controls, class: 'portlet-control-item') end end if closable controls_content << content_tag(:span, nil, class: 'portlet-indicator') end if controls_content.present? controls_wrapper = content_tag(:div, controls_content, class: 'portlet-controls') end # This determines if the portlet should be expanded by default. If it is explicitly given that # takes precedence. If not, by default all remote portlets are not expanded and all static # portlets are. = .key?(:expand) ? [:expand] : block_given? if portlet_html[:class] << 'expanded' portlet_html[:data][:expand] = true end heading_content = content_tag(:div, heading_html) do (icon || ''.html_safe) + content_tag(:h4, title) + (controls_wrapper || ''.html_safe) end body_content = content_tag(:div, (capture(&block) if block_given?), body_html) content_tag(:div, portlet_html) do heading_content + body_content end end |