Module: RailsBootstrapHelpers::Helpers::ButtonHelper

Defined in:
lib/rails-bootstrap-helpers/helpers/button_helper.rb

Instance Method Summary collapse

Instance Method Details

#bs_button_to(*args, &block) ⇒ Object

Renders a Bootstrap button. This method behaves just as “link_to” but will render a Bootstrap button instead of a regular link. Note that this is still an “a” tag and not an “input” tag. In addition to the options “link_to” handles this method also handles the following options:

Options

Parameters:

  • :style (String, Symbol)

    the style of the button

  • :size ("large", "small", "mini")

    the size of the button

  • :disabled (Boolean)

    if the button should be disabled or not

  • :icon (String)

    the name of an icon to render on the button

  • :icon_position ("left", "right")

    the position of the icon, if present



15
16
17
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 15

def bs_button_to (*args, &block)
  RailsBootstrapHelpers::Renderers::ButtonRenderer.new(self, :link, *args, &block).render
end

#bs_inline_button_to(url, icon, options = {}) ⇒ Object

Renders an inline Bootstrap button. That is, a small button having only an icon and no text.

Parameters:

  • url (String)

    the URL the button should link to

  • icon (String)

    the icon of the button

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

    a hash of options. See bs_button_to

See Also:



27
28
29
30
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 27

def bs_inline_button_to (url, icon, options = {})
  options = options.reverse_merge icon: icon, size: "mini"
  RailsBootstrapHelpers::Renderers::ButtonRenderer.new(self, :link, nil, url, options).render
end

#bs_popover_button(name, content_or_options = nil, options = {}, &block) ⇒ Object

Renders a Bootstrap button with a popover.

Options

Parameters:

  • name (String)

    the name/title of the button

  • content_or_options (String, Hash) (defaults to: nil)

    a hash of options if a block is passed, otherwise the content of the popover

  • block (block)

    a block rendering the content of the popover

  • :placement (String, "bottom", "top", "left", "right")


42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 42

def bs_popover_button (name, content_or_options = nil, options = {}, &block)
  if block_given?
    bs_popover_button(name, capture(&block).gsub("\n", ""), content_or_options || {})
  else
    placement = options.delete(:placement) || "bottom"

    options = options.reverse_merge :"data-content" => content_or_options,
      :"data-toggle" => "popover",
      :"data-placement" => placement

    bs_button_to(name, '#', options)
  end
end