Class: PureAdmin::DetailsPanelHelper::DetailsPanelBuilder
- Inherits:
-
Object
- Object
- PureAdmin::DetailsPanelHelper::DetailsPanelBuilder
- 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
-
#resource ⇒ Object
readonly
The resource to build the panel for.
Instance Method Summary collapse
-
#initialize(resource, helper) { ... } ⇒ DetailsPanelBuilder
constructor
Creates an instance of DetailsPanelBuilder.
-
#item(attribute, options = {}) { ... } ⇒ Object
Renders a “details panel item” inside the “details panel” using a custom DSL.
Constructor Details
#initialize(resource, helper) { ... } ⇒ DetailsPanelBuilder
Creates an 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
#resource ⇒ Object (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.
102 103 104 105 106 107 108 109 110 |
# File 'app/helpers/pure_admin/details_panel_helper.rb', line 102 def item(attribute, = {}, &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, , &block) else helper.details_panel_item(human_attribute_name || attribute, resource.send(attribute), ) end end |