module Arbre::Element::BuilderMethods

Public Instance Methods

build_tag(klass, *args, &block) click to toggle source

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

# 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) click to toggle source
# 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) click to toggle source

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" }
# 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