Class: EasyAdmin::Layouts::Builders::ShowLayoutBuilder

Inherits:
BaseLayoutBuilder show all
Defined in:
lib/easy_admin/layouts/builders/show_layout_builder.rb

Overview

Builder specifically for show page layouts

Instance Attribute Summary

Attributes inherited from BaseLayoutBuilder

#current_container_stack, #resource_class, #root_node

Instance Method Summary collapse

Methods inherited from BaseLayoutBuilder

#add_node, #belongs_to_field, #boolean_field, #build, #current_container, #date_field, #datetime_field, #divider, #email_field, #field, #fields, #file_field, #grid, #has_many_field, #id_field, #json_field, #method_missing, #number_field, #password_field, #render, #respond_to_missing?, #section, #select_field, #spacer, #tabs, #text_field, #textarea_field, #with_container

Constructor Details

#initialize(resource_class: nil) ⇒ ShowLayoutBuilder

Returns a new instance of ShowLayoutBuilder.



6
7
8
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 6

def initialize(resource_class: nil)
  super(:show, resource_class: resource_class)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EasyAdmin::Layouts::Builders::BaseLayoutBuilder

Instance Method Details

#action_bar(**attributes, &block) ⇒ Object

Add an action bar



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 60

def action_bar(**attributes, &block)
  action_bar_node = Nodes::ActionBar.new(attributes)
  add_node(action_bar_node)
  
  if block_given?
    @current_container_stack.push(action_bar_node)
    action_builder = ActionBarBuilder.new(self, action_bar_node)
    action_builder.instance_exec(&block)
    @current_container_stack.pop
  end
  
  action_bar_node
end

#badge(text, variant: :default, **attributes) ⇒ Object

Add badge



91
92
93
94
95
96
97
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 91

def badge(text, variant: :default, **attributes)
  badge_node = Nodes::Badge.new(
    text,
    attributes.merge(variant: variant)
  )
  add_node(badge_node)
end

#card(title: nil, **attributes, &block) ⇒ Object

Add a card component



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 26

def card(title: nil, **attributes, &block)
  card_node = Nodes::Card.new(title: title, **attributes)
  
  if block_given?
    with_container(card_node, &block)
  else
    add_node(card_node)
  end
  
  card_node
end

#column(**attributes, &block) ⇒ Object

Add column layout



129
130
131
132
133
134
135
136
137
138
139
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 129

def column(**attributes, &block)
  column_node = Nodes::Column.new(attributes)
  
  if block_given?
    with_container(column_node, &block)
  else
    add_node(column_node)
  end
  
  column_node
end

#content(&block) ⇒ Object

Add content block



148
149
150
151
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 148

def content(&block)
  content_node = Nodes::Content.new(block: block)
  add_node(content_node)
end

#description_list(**attributes, &block) ⇒ Object

Add a description list for key-value pairs



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 13

def description_list(**attributes, &block)
  dl_node = Nodes::DescriptionList.new(attributes)
  
  if block_given?
    with_container(dl_node, &block)
  else
    add_node(dl_node)
  end
  
  dl_node
end

#heading(text, level: 2, **attributes) ⇒ Object

Add heading



142
143
144
145
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 142

def heading(text, level: 2, **attributes)
  heading_node = Nodes::Heading.new(text, attributes.merge(level: level))
  add_node(heading_node)
end

#metric(label:, value:, **attributes) ⇒ Object

Add a metric card



39
40
41
42
43
44
45
46
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 39

def metric(label:, value:, **attributes)
  metric_node = Nodes::MetricCard.new(
    label: label,
    value: value,
    **attributes
  )
  add_node(metric_node)
end

#metric_card(title: nil, label: nil, value: nil, **attributes) ⇒ Object

Add a metric card (accepts both label and title)



49
50
51
52
53
54
55
56
57
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 49

def metric_card(title: nil, label: nil, value: nil, **attributes)
  metric_node = Nodes::MetricCard.new(
    title: title,
    label: label,
    value: value,
    **attributes
  )
  add_node(metric_node)
end

#panel(title, expanded: true, **attributes, &block) ⇒ Object

Add a panel (collapsible section)



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 75

def panel(title, expanded: true, **attributes, &block)
  panel_node = Nodes::Panel.new(
    title,
    attributes.merge(expanded: expanded)
  )
  
  if block_given?
    with_container(panel_node, &block)
  else
    add_node(panel_node)
  end
  
  panel_node
end

Add related resources section



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 100

def related(resource_name, **attributes, &block)
  related_node = Nodes::RelatedResources.new(
    resource_name,
    attributes
  )
  
  if block_given?
    with_container(related_node, &block)
  else
    add_node(related_node)
  end
  
  related_node
end

#row(**attributes, &block) ⇒ Object

Add row layout



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/easy_admin/layouts/builders/show_layout_builder.rb', line 116

def row(**attributes, &block)
  row_node = Nodes::Row.new(attributes)
  
  if block_given?
    with_container(row_node, &block)
  else
    add_node(row_node)
  end
  
  row_node
end