Class: Bootstrap::TagMethod

Inherits:
Object show all
Includes:
Content
Defined in:
card-mod-bootstrap/lib/bootstrap/tag_method.rb

Overview

support html tag generation

Instance Method Summary collapse

Constructor Details

#initialize(component, name, html_class, tag_opts = {}, &tag_block) ⇒ TagMethod

Returns a new instance of TagMethod.



6
7
8
9
10
11
12
13
14
15
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 6

def initialize component, name, html_class, tag_opts={}, &tag_block
  @component = component
  @name = name
  @html_class = html_class
  @tag_opts = tag_opts
  @tag_block = tag_block
  @append = []
  @wrap = []
  @xm = Builder::XmlMarkup.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



26
27
28
29
30
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 26

def method_missing method, *args, &block
  return super unless respond_to_missing? method

  @component.send method, *args, &block
end

Instance Method Details

#append(&block) ⇒ Object



46
47
48
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 46

def append &block
  @append[-1] << block
end

#call(*_args, &content_block) ⇒ Object



17
18
19
20
21
22
23
24
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 17

def call *_args, &content_block
  component.content.push "".html_safe

  opts = process_content(&content_block)
  process_collected_content tag_name, opts
  process_append
  ""
end

#prepend(&block) ⇒ Object



36
37
38
39
40
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 36

def prepend &block
  tmp = @content.pop
  instance_exec(&block)
  @content << tmp
end

#respond_to_missing?(method, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 32

def respond_to_missing? method, _include_private=false
  @component.respond_to? method
end

#wrap(&block) ⇒ Object



42
43
44
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 42

def wrap &block
  instance_exec(&block)
end

#wrapInner(tag = nil, &block) ⇒ Object



50
51
52
# File 'card-mod-bootstrap/lib/bootstrap/tag_method.rb', line 50

def wrapInner tag=nil, &block
  @wrap[-1] << (block_given? ? block : tag)
end