Class: Phlexi::Display::Base
Overview
A display component for rendering flexible and customizable data views.
Direct Known Subclasses
Defined Under Namespace
Instance Attribute Summary collapse
-
#key ⇒ Symbol
readonly
The display's key, derived from the record or explicitly set.
-
#object ⇒ ActiveModel::Model?
readonly
The display's associated object.
Class Method Summary collapse
Instance Method Summary collapse
-
#display_template ⇒ void
Executes the display's content block.
-
#initialize(record, attributes: {}, **options) ⇒ Base
constructor
Initializes a new Display instance.
-
#view_template ⇒ void
Renders the display template.
Constructor Details
#initialize(record, attributes: {}, **options) ⇒ Base
Initializes a new Display instance.
43 44 45 46 47 48 49 50 51 |
# File 'lib/phlexi/display/base.rb', line 43 def initialize(record, attributes: {}, **) @attributes = attributes @namespace_klass = .delete(:namespace_klass) || self.class::Namespace @builder_klass = .delete(:builder_klass) || self.class::Builder @options = initialize_object_and_key(record) initialize_namespace end |
Instance Attribute Details
#key ⇒ Symbol (readonly)
The display's key, derived from the record or explicitly set
18 19 20 |
# File 'lib/phlexi/display/base.rb', line 18 def key @key end |
#object ⇒ ActiveModel::Model? (readonly)
The display's associated object
18 19 20 |
# File 'lib/phlexi/display/base.rb', line 18 def object @object end |
Class Method Details
.inline(&block) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/phlexi/display/base.rb', line 23 def self.inline(*, **, &block) raise ArgumentError, "block is required" unless block new(*, **) do |f| f.instance_exec(&block) end end |
Instance Method Details
#display_template ⇒ void
This method returns an undefined value.
Executes the display's content block. Override this in subclasses to define a static display.
64 65 66 |
# File 'lib/phlexi/display/base.rb', line 64 def display_template yield if block_given? end |
#view_template ⇒ void
This method returns an undefined value.
Renders the display template.
56 57 58 |
# File 'lib/phlexi/display/base.rb', line 56 def view_template(&) display_wrapper { display_template(&) } end |