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
-
.component(item) ⇒ Object
Creates components from the registry.
-
.included(base) ⇒ Object
Runs for included classes.
Instance Method Summary collapse
-
#component(name, comp, options = {}, &block) ⇒ Object
Creates a child component.
Class Method Details
.component(item) ⇒ Object
Creates components from the registry
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
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
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, = {}, &block) component = comp.is_a?(Class) ? comp.new(nil) : Component.new(comp) component.instance_eval(&block) if block .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 |