Module: Arbre::Element::BuilderMethods

Defined in:
lib/arbre/patches.rb

Instance Method Summary collapse

Instance Method Details

#build_tag(klass, *args, &block) ⇒ Object

we do not want to check the arity of the block in express templates because components are expected to be able to contain other components or template code without use of a builder style syntax



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/arbre/patches.rb', line 16

def build_tag(klass, *args, &block)
  return if should_supress_output?(args)
  tag = klass.new(arbre_context)
  tag.parent = current_arbre_element

  with_current_arbre_element tag do
    # begin
      tag.build(*args, &block)
    # rescue Exception => e
    #   on_component_error(tag, e)
    # end
  end

  tag
end

#on_component_error(tag, exception) ⇒ Object



48
49
50
51
52
# File 'lib/arbre/patches.rb', line 48

def on_component_error(tag, exception)
  tag.content = "Error rendering #{tag.class} component: #{exception.message}"
  ::Rails.logger.error exception
  ::Rails.logger.error exception.backtrace.slice(0..20).join("\n")
end

#should_supress_output?(args) ⇒ Boolean

Conditionally do not emit markup Example that would supress generation of the h2 markup:

* h2(only_when: false) { "Some text" }
* h2(unless: true) { "Some text" }

Returns:

  • (Boolean)


36
37
38
39
40
41
42
43
44
45
# File 'lib/arbre/patches.rb', line 36

def should_supress_output?(args)
  if args.last.kind_of?(Hash)
    only_when = args.last.delete(:only_when)
    unless_condition = args.delete(:unless)
    return true if only_when === false
    return true if !unless_condition.nil? && !!unless_condition
  else
    false
  end
end