Class: EasyAdmin::Layouts::Nodes::BaseNode
- Inherits:
-
Object
- Object
- EasyAdmin::Layouts::Nodes::BaseNode
- Defined in:
- lib/easy_admin/layouts/nodes/base_node.rb
Overview
Base class for all layout AST nodes
Direct Known Subclasses
Action, ActionBar, Badge, Card, Column, ConditionalFields, Content, DescriptionList, Divider, Dropdown, ErrorsSummary, FieldNode, Fieldset, FormAction, FormActions, Grid, Heading, HelpText, InlineFields, MetricCard, NestedFields, Panel, RelatedResources, RenderNode, Root, Row, Section, Spacer, Tab, Tabs
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#visible_if ⇒ Object
readonly
Returns the value of attribute visible_if.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Get attribute value.
-
#[]=(key, value) ⇒ Object
Set attribute value.
-
#accept(visitor, context) ⇒ Object
Accept visitor for traversal.
-
#add_child(node) ⇒ Object
Add child node.
-
#children? ⇒ Boolean
Check if node has children.
-
#initialize(attributes = {}, &block) ⇒ BaseNode
constructor
A new instance of BaseNode.
-
#node_type ⇒ Object
Node type for identification.
-
#visible?(context) ⇒ Boolean
Check if node should be visible based on context.
Constructor Details
#initialize(attributes = {}, &block) ⇒ BaseNode
Returns a new instance of BaseNode.
8 9 10 11 12 13 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 8 def initialize(attributes = {}, &block) @attributes = attributes.dup @visible_if = @attributes.delete(:visible_if) @metadata = @attributes.delete(:metadata) || {} @children = [] end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 6 def attributes @attributes end |
#children ⇒ Object (readonly)
Returns the value of attribute children.
6 7 8 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 6 def children @children end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 6 def @metadata end |
#visible_if ⇒ Object (readonly)
Returns the value of attribute visible_if.
6 7 8 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 6 def visible_if @visible_if end |
Instance Method Details
#[](key) ⇒ Object
Get attribute value
48 49 50 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 48 def [](key) @attributes[key] end |
#[]=(key, value) ⇒ Object
Set attribute value
53 54 55 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 53 def []=(key, value) @attributes[key] = value end |
#accept(visitor, context) ⇒ Object
Accept visitor for traversal
38 39 40 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 38 def accept(visitor, context) visitor.visit(self, context) if visible?(context) end |
#add_child(node) ⇒ Object
Add child node
43 44 45 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 43 def add_child(node) @children << node if node.is_a?(BaseNode) end |
#children? ⇒ Boolean
Check if node has children
58 59 60 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 58 def children? @children.any? end |
#node_type ⇒ Object
Node type for identification
63 64 65 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 63 def node_type self.class.name.demodulize.underscore.to_sym end |
#visible?(context) ⇒ Boolean
Check if node should be visible based on context
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/easy_admin/layouts/nodes/base_node.rb', line 16 def visible?(context) return true unless visible_if case visible_if when Proc # Evaluate in safe context context.instance_exec(&visible_if) when Symbol # Call method on record context.record.public_send(visible_if) if context.record.respond_to?(visible_if) when String # Evaluate as method chain (e.g., "record.published?") eval_method_chain(context, visible_if) else # Direct boolean value !!visible_if end rescue => e true # Default to visible on error end |