Class: Card::Bootstrap::OldComponent

Inherits:
Component show all
Includes:
Content, Delegate
Defined in:
mod/bootstrap/lib/card/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 ComponentKlass

#def_div_method, #def_tag_method

Constructor Details

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

Returns a new instance of OldComponent.



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

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 Card::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



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

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



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'mod/bootstrap/lib/card/bootstrap/old_component.rb', line 39

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



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

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

Instance Method Details

#renderObject



63
64
65
66
67
68
# File 'mod/bootstrap/lib/card/bootstrap/old_component.rb', line 63

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