Class: EasyAdmin::Layouts::Nodes::RenderNode
- Defined in:
- lib/easy_admin/layouts/nodes/render_node.rb
Overview
Node for rendering custom components
Instance Attribute Summary
Attributes inherited from BaseNode
#attributes, #children, #metadata, #visible_if
Instance Method Summary collapse
-
#build_component(context) ⇒ Object
Instantiate the component with props and context.
- #component_class ⇒ Object
-
#initialize(component_class, props = {}) ⇒ RenderNode
constructor
A new instance of RenderNode.
- #props ⇒ Object
Methods inherited from BaseNode
#[], #[]=, #accept, #add_child, #children?, #node_type, #visible?
Constructor Details
#initialize(component_class, props = {}) ⇒ RenderNode
Returns a new instance of RenderNode.
6 7 8 9 10 11 |
# File 'lib/easy_admin/layouts/nodes/render_node.rb', line 6 def initialize(component_class, props = {}) attributes = props.dup super(attributes) @component_class = component_class @props = attributes end |
Instance Method Details
#build_component(context) ⇒ Object
Instantiate the component with props and context
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/easy_admin/layouts/nodes/render_node.rb', line 22 def build_component(context) # Merge context into props if component accepts it component_props = @props.dup # Add standard context props if not already present component_props[:record] ||= context.record if context.respond_to?(:record) component_props[:resource_class] ||= context.resource_class if context.respond_to?(:resource_class) component_props[:current_user] ||= context.current_user if context.respond_to?(:current_user) # Handle form builder for form contexts if context.respond_to?(:form_builder) && context.form_builder component_props[:form] ||= context.form_builder end @component_class.new(**component_props) end |
#component_class ⇒ Object
13 14 15 |
# File 'lib/easy_admin/layouts/nodes/render_node.rb', line 13 def component_class @component_class end |
#props ⇒ Object
17 18 19 |
# File 'lib/easy_admin/layouts/nodes/render_node.rb', line 17 def props @props end |