Class: OkonomiUiKit::UiHelper::UiBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::CaptureHelper, ActionView::Helpers::TagHelper
Defined in:
app/helpers/okonomi_ui_kit/ui_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, namespace: OkonomiUiKit::Components) ⇒ UiBuilder

Returns a new instance of UiBuilder.



13
14
15
16
# File 'app/helpers/okonomi_ui_kit/ui_helper.rb', line 13

def initialize(template, namespace: OkonomiUiKit::Components)
  @template = template
  @namespace = namespace
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/helpers/okonomi_ui_kit/ui_helper.rb', line 18

def method_missing(method_name, *args, &block)
  component = resolve_component(method_name)

  if component
    component.render(*args, &block)
  else
    super
  end
end

Instance Attribute Details

#namespace ⇒ Object (readonly)

Returns the value of attribute namespace.



11
12
13
# File 'app/helpers/okonomi_ui_kit/ui_helper.rb', line 11

def namespace
  @namespace
end

#template ⇒ Object (readonly)

Returns the value of attribute template.



11
12
13
# File 'app/helpers/okonomi_ui_kit/ui_helper.rb', line 11

def template
  @template
end

Instance Method Details

#forms ⇒ Object



36
37
38
# File 'app/helpers/okonomi_ui_kit/ui_helper.rb', line 36

def forms
  @forms ||= self.class.new(@template, namespace: OkonomiUiKit::Components::Forms)
end

#resolve_component(name) ⇒ Object



28
29
30
31
32
33
34
# File 'app/helpers/okonomi_ui_kit/ui_helper.rb', line 28

def resolve_component(name)
  component_name = "#{namespace.name}::#{name.to_s.camelize}"

  return nil unless Object.const_defined?(component_name)

  component_name.constantize.new(@template)
end