Module: RailsBootstrapHelpers::Helpers::ButtonHelper

Includes:
FormTagHelper, OptionsHelper
Defined in:
lib/rails-bootstrap-helpers/helpers/button_helper.rb

Instance Method Summary collapse

Methods included from FormTagHelper

#bs_button_tag, #bs_submit_tag

Methods included from OptionsHelper

#append_class!, #bs_options

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:

Parameters:

  • options (Hash)

    a customizable set of options



18
19
20
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 18

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

#bs_collapsible_button(text, target, options = {}) ⇒ Object

Renders a collapsible Bootstrap button. That is, a button when clicked opens a collapsible section.

Parameters:

  • text (String)

    the text of the button

  • target (String)

    a selector matching the

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

    a hash of options. All options are passed straight through to the underlying bs_button_to method.

See Also:



78
79
80
81
82
83
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 78

def bs_collapsible_button (text, target, options = {})
  options = options.dup.reverse_merge :"data-toggle" => "collapse",
    :"data-target" => target

  bs_button_tag text, :button, options
end

#bs_dropdown_button_to(text, url_or_options = nil, options = {}, &block) ⇒ Object

Renders a dropdown button.

All options are passed to the underlying button.

Parameters:

  • text (String)

    the text of the button

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

    if a string, the button will be rendered as split dropdown button. This argument will be interpreted as the URL of the button. If an Hash, it will be interpreted as the options for the button an a normal dropdown button will be rendered.

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

    if the an URL is passed as the “url_or_options” argument this will will be interpreted a hash of options. Otherwise it will be ignored.

  • block (Proc)

    the block should render a the dropdown menu items in the form of list items with links.



124
125
126
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 124

def bs_dropdown_button_to (text, url_or_options = nil, options = {}, &block)
  RailsBootstrapHelpers::Renderers::DropdownButtonRenderer.new(self, text, url_or_options, options, &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:



30
31
32
33
34
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 30

def bs_inline_button_to (url, icon, options = {})
  options = options.reverse_merge icon: icon, size: "mini"
  append_class!(options, "inline")
  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.

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

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

    a customizable set of options

Options Hash (options):

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

    the position of the popover

See Also:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 48

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
    options = options.deep_dup
    placement = options.delete(:placement)

    if placement
      ActiveSupport::Deprecation.warn "Usage of the option `:placement` is deprecated. Please use the `:position` option instead"
    end

    position = options.delete(:position) || placement || "bottom"

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

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

#button_group(options = {}, &block) ⇒ Object

Returns a button group. That is, a div tag with the “btn-group” class.

All other options are passed to the button group div.

Parameters:

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

    a hash of options.

Options Hash (options):

  • :vertical (Boolean) — default: false

    if true, appends the “btn-group-vertical” class

  • :toolbar (Boolean) — default: false

    if true, wraps the group in an another group with the “btn-toolbar” class



96
97
98
99
100
101
102
103
104
105
# File 'lib/rails-bootstrap-helpers/helpers/button_helper.rb', line 96

def button_group (options = {}, &block)
  if toolbar = options.delete(:toolbar)
    append_class!(options, "btn-toolbar")
  else
    append_class!(options, "btn-group")
    append_class!(options, "btn-group-vertical") if options.delete(:vertical)
  end

  (:div, options, &block)
end