Module: Fron::Behaviors::Components

Included in:
Component
Defined in:
opal/fron/core/behaviors/components.rb

Overview

Behavior for composing and creating child components.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.component(item) ⇒ Object

Creates components from the registry

Parameters:

  • item (Array)

    Component directive



15
16
17
18
19
# File 'opal/fron/core/behaviors/components.rb', line 15

def self.component(item)
  arguments = item[:args].dup
  block = item[:block]
  component(*arguments, &block)
end

.included(base) ⇒ Object

Runs for included classes

Parameters:

  • base (Class)

    The class



8
9
10
# File 'opal/fron/core/behaviors/components.rb', line 8

def self.included(base)
  base.register self, [:component]
end

Instance Method Details

#component(name, comp, options = {}, &block) ⇒ Object

Creates a child component

:reek:TooManyStatements

Parameters:

  • name (String)

    The name of the component

  • comp (Class)

    The component

  • block (Proc)

    The block to eval on the new component



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'opal/fron/core/behaviors/components.rb', line 28

def component(name, comp, options = {}, &block)
  component = comp.is_a?(Class) ? comp.new(nil) : Component.new(comp)
  component.instance_eval(&block) if block

  options.each do |key, value|
    if component.respond_to?("#{key}=")
      component.send("#{key}=", value)
    else
      component[key] = value
    end
  end

  self << component
  instance_variable_set "@#{name}", component

  return if respond_to?(name)
  define_singleton_method name do
    instance_variable_get("@#{name}")
  end
end