Module: PureAdmin::DetailsPanelHelper

Defined in:
app/helpers/pure_admin/details_panel_helper.rb

Overview

Helper methods for the details panel.

Defined Under Namespace

Classes: DetailsPanelBuilder

Instance Method Summary collapse

Instance Method Details

#details_panel(options = {}) { ... } ⇒ Object

Renders a “details panel” to the view.

Parameters:

  • options (Hash) (defaults to: {})

    all options that can be passed to content_tag are respected here.

Yields:

  • The contents of the details panel



8
9
10
11
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 8

def details_panel(options = {}, &block)
  options[:class] = merge_html_classes('pure-g details-panel', options[:class])
  (:div, options, &block)
end

#details_panel_controls(options = {}) { ... } ⇒ Object

Renders a “details_panel_controls” element to the view.

Parameters:

  • options (Hash) (defaults to: {})

    all options that can be passed to content_tag are respected here.

Yields:

  • The contents of the details panel controls



54
55
56
57
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 54

def details_panel_controls(options = {}, &block)
  options[:class] = merge_html_classes('details-panel-controls', options[:class])
  (:div, capture(&block), options)
end

#details_panel_for(resource, options = {}) { ... } ⇒ Object

Renders a “details panel” to the view using the details panel builder DSL.

Parameters:

  • resource (ActiveRecord::Base)

    the model instance to build the details panel for.

  • options (Hash) (defaults to: {})

    all options that can be passed to content_tag are respected here.

Yields:

  • The contents of the details panel



64
65
66
67
68
69
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 64

def details_panel_for(resource, options = {}, &block)
  builder = DetailsPanelBuilder.new(resource, self)
  details_panel(options) do
    capture(builder, &block)
  end
end

#details_panel_heading(title = nil, options = nil) { ... } ⇒ Object

Renders a “details panel heading” to the view.

Parameters:

  • title (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

    all options that can be passed to content_tag are respected here.

Yields:

  • The contents of the details panel heading



18
19
20
21
22
23
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 18

def details_panel_heading(title = nil, options = nil, &block)
  options, title = title, capture(&block) if block_given?
  options = options || {}
  options[:class] = merge_html_classes('pure-u details-panel-heading', options[:class])
  (:h4, title, options)
end

#details_panel_item(label, value = nil, options = nil) { ... } ⇒ Object

Renders a “details panel item” to the view.

Parameters:

  • label (String, Symbol)
  • value (Any) (defaults to: nil)
  • options (Hash) (defaults to: nil)

    all options that can be passed to content_tag are respected here.

Yields:

  • The contents of the details panel item



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 31

def details_panel_item(label, value = nil, options = nil, &block)
  options, value = value, capture(&block) if block_given?
  options = options || {}

  label = label.to_s.titleize unless label.nil? || label.respond_to?(:titleize)

  item_html = options.delete(:item_html) || {}
  item_html[:class] = merge_html_classes('details-panel-item pure-u-1', item_html[:class])

  label_html = options.delete(:label_html) || {}

  value = value.try(:to_s)
  value =  :span, '(blank)', class: 'text-muted' unless value.present?

  (:div, item_html) do
    (:label, label, label_html) + value
  end
end