Class: Bootstrap::Component

Inherits:
Object
  • Object
show all
Includes:
BasicTags, Delegate
Defined in:
mod/bootstrap/lib/bootstrap/component.rb,
mod/bootstrap/lib/bootstrap/component/form.rb,
mod/bootstrap/lib/bootstrap/component/panel.rb,
mod/bootstrap/lib/bootstrap/component/layout.rb,
mod/bootstrap/lib/bootstrap/component/horizontal_form.rb

Direct Known Subclasses

Form, Layout, Panel

Defined Under Namespace

Classes: Form, HorizontalForm, Layout, Panel

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Delegate

#method_missing, #respond_to_missing?

Methods included from BasicTags

#html

Constructor Details

#initialize(context, *args, &block) ⇒ Component

Returns a new instance of Component.



4
5
6
7
8
9
10
11
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 4

def initialize context, *args, &block
  @context = context
  @content = ["".html_safe]
  @args = args
  @child_args = []
  @append = []
  @build_block = block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Bootstrap::Delegate

Class Method Details

.add_div_method(name, html_class, opts = {}, &tag_block) ⇒ Object



18
19
20
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 18

def add_div_method name, html_class, opts={}, &tag_block
  add_tag_method name, html_class, opts.merge(tag: :div), &tag_block
end

.add_tag_method(name, html_class, tag_opts = {}, &tag_block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 22

def add_tag_method name, html_class, tag_opts={}, &tag_block
  define_method name do |*args, &block|
    process_tag tag_opts[:tag] || name do
      content, opts, new_child_args = standardize_args args, &tag_block
      add_classes opts, html_class, tag_opts.delete(:optional_classes)
      if (attributes = tag_opts.delete(:attributes))
        opts.merge! attributes
      end

      content = with_child_args new_child_args do
        generate_content content,
                         tag_opts[:content_processor],
                         &block
      end

      [content, opts]
    end
  end
end

.render(format, *args, &block) ⇒ Object



14
15
16
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 14

def render format, *args, &block
  new(format, *args, &block).render
end

Instance Method Details

#append(&block) ⇒ Object



60
61
62
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 60

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

#insert(&block) ⇒ Object



56
57
58
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 56

def insert &block
  instance_exec &block
end

#prepend(&block) ⇒ Object



50
51
52
53
54
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 50

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

#renderObject



43
44
45
46
47
48
# File 'mod/bootstrap/lib/bootstrap/component.rb', line 43

def render
  @rendered = begin
    render_content
    @content[-1]
  end
end