Module: Arbo::Element::BuilderMethods

Included in:
Arbo::Element
Defined in:
lib/arbo/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/arbo/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/arbo/element/builder_methods.rb', line 22

def build_tag(klass, *args, &block)
  tag = klass.new(arbo_context)
  tag.parent = current_arbo_element

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

  tag
end

#current_arbo_elementObject



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

def current_arbo_element
  arbo_context.current_arbo_element
end

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



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

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

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



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

def with_current_arbo_element(tag, &block)
  arbo_context.with_current_arbo_element(tag, &block)
end