Class: PartialsFx::Component

Inherits:
Object
  • Object
show all
Extended by:
Attributes::ClassMethods, Slots::ClassMethods, Styles::ClassMethods
Includes:
ActionView::Helpers::TagHelper, ActiveModel::Attributes, ActiveModel::Model, Render, Styles
Defined in:
lib/partials_fx/component.rb,
lib/partials_fx/component/slots.rb,
lib/partials_fx/component/render.rb,
lib/partials_fx/component/styles.rb,
lib/partials_fx/component/attributes.rb

Defined Under Namespace

Modules: Attributes, Render, Slots, Styles

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Attributes::ClassMethods

attribute, required_attributes

Methods included from Slots::ClassMethods

slot

Methods included from Styles::ClassMethods

component_styles, register_styles, styles

Methods included from Render

#render_in

Methods included from Styles

#component_class

Constructor Details

#initialize(**component_attributes) ⇒ Component

Returns a new instance of Component.



36
37
38
39
40
# File 'lib/partials_fx/component.rb', line 36

def initialize(**component_attributes)
  validate_required_attributes(component_attributes)

  super
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *arguments, &block) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/partials_fx/component.rb', line 51

def method_missing(method, *arguments, &block)
  if respond_to_missing?(method)
    public_send(method, *arguments, &block)
  else
    super
  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



24
25
26
# File 'lib/partials_fx/component.rb', line 24

def content
  @content
end

#view_contextObject

Returns the value of attribute view_context.



24
25
26
# File 'lib/partials_fx/component.rb', line 24

def view_context
  @view_context
end

Class Method Details

.inherited(subclass) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/partials_fx/component.rb', line 27

def inherited(subclass)
  super

  subclass.instance_eval do
    @pending_registration = true
  end
end

Instance Method Details

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/partials_fx/component.rb', line 59

def respond_to_missing?(method, include_private = false)
  public_methods.include?(method) || super
end

#to_localsObject



42
43
44
45
46
47
48
49
# File 'lib/partials_fx/component.rb', line 42

def to_locals
  base_locals = attributes.transform_keys(&:to_sym)

  base_locals
    .merge(public_methods(false).to_h { [_1, public_send(_1)] })
    .merge(slot_locals)
    .merge(content: content, component_class: component_class)
end