Module: Cedar::Component

Includes:
Arbre::HTML
Defined in:
lib/cedar/component.rb

Overview

InlineRender provides a ‘render` dsl to your components which will render any arbre tree within.

It will also convert snake case component names to component instances for example, this would be equivalent to ‘ButtonComponent.new(label: “Test”)`

“‘ruby render do

div do
  button label: "Test"
end

end “‘

Instance Method Summary collapse

Instance Method Details

#find_component(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/cedar/component.rb', line 31

def find_component(name)
  if const_defined?(name)
    const_get(name)
  else
    if superclass.respond_to?(:find_component)
      superclass.find_component(name)
    else
      adjusted_name = name.chomp("Component").underscore
      raise(NameError, "undefined local variable or method `#{adjusted_name}` for #{self}")
    end

  end
end

#render(&blk) ⇒ Object

The empty first arg is just to trick rubymine when using ‘render` inside the arbre context



24
25
26
27
28
29
# File 'lib/cedar/component.rb', line 24

def render(&blk)
  define_method :call do
    ctx = Context.new(self)
    ctx.instance_eval(&blk).to_s
  end
end