Class: BulmaPhlex::Rails::BaseDisplay

Inherits:
Base
  • Object
show all
Defined in:
lib/bulma_phlex/rails/components/displays/base_display.rb

Overview

# Base Display

Base class for read-only display fields styled with Bulma.

This allows the model to be passed via the ‘model:` option or as the first argument. When the model is passed as an option, the method is assumed to be the first argument.

Direct Known Subclasses

CurrencyDisplay, TextDisplay

Constant Summary collapse

FORM_FIELD_OPTIONS =

Keyword arguments accepted by BulmaPhlex::FormField

BulmaPhlex::FormField
.instance_method(:initialize)
.parameters
.map { |_, name| name }
.freeze

Instance Method Summary collapse

Constructor Details

#initialize(model, method = nil, **options) ⇒ BaseDisplay

Returns a new instance of BaseDisplay.



20
21
22
23
24
# File 'lib/bulma_phlex/rails/components/displays/base_display.rb', line 20

def initialize(model, method = nil, **options)
  @model = options.fetch(:model, model)
  @method = method || model
  @options = options
end

Instance Method Details

#view_templateObject



26
27
28
29
30
31
32
# File 'lib/bulma_phlex/rails/components/displays/base_display.rb', line 26

def view_template
  form_field_options = @options.slice(*FORM_FIELD_OPTIONS)
  BulmaPhlex::FormField(**form_field_options) do |field|
    field.label { label(class: "label") { label_text } }
    field.control { control_content }
  end
end