Module: Arbre::Element::BuilderMethods

Included in:
Arbre::Element
Defined in:
lib/arbre/element/builder_methods.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



6
7
8
# File 'lib/arbre/element/builder_methods.rb', line 6

def self.included(klass)
  klass.extend ClassMethods
end

Instance Method Details

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/arbre/element/builder_methods.rb', line 22

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

  with_current_arbre_element tag do
    if block && block.arity > 0
      tag.build(*args, &block)
    else
      tag.build(*args)
      append_return_block(yield) if block
    end
  end

  tag
end

#current_arbre_elementObject



44
45
46
# File 'lib/arbre/element/builder_methods.rb', line 44

def current_arbre_element
  arbre_context.current_arbre_element
end

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



38
39
40
41
42
# File 'lib/arbre/element/builder_methods.rb', line 38

def insert_tag(klass, *args, &block)
  tag = build_tag(klass, *args, &block)
  current_arbre_element.add_child(tag)
  tag
end

#with_current_arbre_element(tag, &block) ⇒ Object Also known as: within



48
49
50
# File 'lib/arbre/element/builder_methods.rb', line 48

def with_current_arbre_element(tag, &block)
  arbre_context.with_current_arbre_element(tag, &block)
end