Class: Bootstrap::OldComponent

Inherits:
Component show all
Includes:
Content, Delegate
Defined in:
card-mod-bootstrap/lib/bootstrap/old_component.rb

Overview

not-yet-obviated component handling

Direct Known Subclasses

Component::Layout, Component::Panel

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Delegate

#method_missing, #respond_to_missing?

Methods inherited from Component

#append, #card, #insert, #prepend, #wrap

Methods included from Component::ComponentClass

#def_div_method, #def_tag_method

Constructor Details

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

Returns a new instance of OldComponent.



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

def initialize context, *args, &block
  @context = context
  @content = ["".html_safe]
  @args = args
  @child_args = []
  @append = []
  @wrap = []
  @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 Also known as: def_div_method

Like add_tag_method but always generates a div tag The tag option is not available



23
24
25
# File 'card-mod-bootstrap/lib/bootstrap/old_component.rb', line 23

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 Also known as: def_tag_method

Defines a method that generates a html tag

Examples:

add_tag_method :link, "known-link", tag: :a, id: "uniq-link"
link  # => <a class="known-link" id="uniq-link"></a>

Parameters:

  • name (Symbol, String)

    the name of the method. If no :tag option in tag_opts is defined then the name is also the name of the tag that the method generates

  • html_class (String)

    a html class that is added to tag. Use nil if you don’t want a html_class

  • tag_opts (Hash) (defaults to: {})

    additional argument that will be added to the tag

Options Hash (tag_opts):

  • tag (Symbol, String)

    the name of the tag



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'card-mod-bootstrap/lib/bootstrap/old_component.rb', line 35

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



17
18
19
# File 'card-mod-bootstrap/lib/bootstrap/old_component.rb', line 17

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

Instance Method Details

#renderObject



59
60
61
62
63
64
# File 'card-mod-bootstrap/lib/bootstrap/old_component.rb', line 59

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