Class: Card::Bootstrap::OldComponent

Inherits:
Component
  • Object
show all
Includes:
Content, Delegate
Defined in:
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
# File 'lib/card/bootstrap/old_component.rb', line 7

def initialize context, *args, &block
  super
  @html = nil
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



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

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



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

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) ⇒ Object



13
14
15
# File 'lib/card/bootstrap/old_component.rb', line 13

def render(format, ...)
  new(format, ...).render
end

Instance Method Details

#renderObject



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

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