Class: PureAdmin::DetailsPanelHelper::DetailsPanelBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/pure_admin/details_panel_helper.rb

Overview

Allows building of details panels using a custom DSL.

<%= details_panel_for @resource do |dp| %>

<%= dp.item :title %>

<% end %>

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, helper) { ... } ⇒ DetailsPanelBuilder

Creates an instance of DetailsPanelBuilder

Parameters:

  • resource (ActiveRecord::Base)

    the model instance to build the details panel for.

  • helper (ApplicationHelper)

    instance of application helper to allow access to view helpers.

Yields:

  • instance of DetailsPanelBuilder



87
88
89
90
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 87

def initialize(resource, helper)
  @resource = resource
  @helper = helper
end

Instance Attribute Details

#resourceObject (readonly)

The resource to build the panel for.



80
81
82
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 80

def resource
  @resource
end

Instance Method Details

#item(attribute, options = {}) { ... } ⇒ Object

Renders a “details panel item” inside the “details panel” using a custom DSL.

The attribute name is used as the item label with i18n. If a block is passed a custom value can be given for the item. NoMethodError is thrown when the attribute is not present on the resource.

Parameters:

  • attribute (Symbol)

    the attribute on the resource

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

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

Yields:

  • The contents of the details panel item



102
103
104
105
106
107
108
109
110
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 102

def item(attribute, options = {}, &block)
  human_attribute_name = resource.class.human_attribute_name(attribute) if resource.respond_to?(attribute)

  if block_given?
    helper.details_panel_item(human_attribute_name || attribute, options, &block)
  else
    helper.details_panel_item(human_attribute_name || attribute, resource.send(attribute), options)
  end
end