Module: Bootstrap::Component::ComponentClass

Included in:
Bootstrap::Component
Defined in:
card-mod-bootstrap/lib/bootstrap/component/component_class.rb

Overview

class methods for Bootstrap::Component

Instance Method Summary collapse

Instance Method Details

#def_div_method(name, html_class, opts = {}, &tag_block) ⇒ Object

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



11
12
13
# File 'card-mod-bootstrap/lib/bootstrap/component/component_class.rb', line 11

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

#def_tag_method(method_name, html_class, tag_opts = {}, &tag_opts_block) ⇒ Object

Defines a method that generates a html tag

Examples:

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

Parameters:

  • method_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



26
27
28
29
30
31
32
33
# File 'card-mod-bootstrap/lib/bootstrap/component/component_class.rb', line 26

def def_tag_method method_name, html_class, tag_opts={}, &tag_opts_block
  tag = tag_opts.delete(:tag) || method_name
  define_method method_name do |*args, &content_block|
    @html.tag! tag, tag_method_opts(args, html_class, tag_opts, &tag_opts_block) do
      instance_exec(&content_block)
    end
  end
end

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



5
6
7
# File 'card-mod-bootstrap/lib/bootstrap/component/component_class.rb', line 5

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