Module: UrlHelper

Defined in:
app/helpers/url_helper.rb

Constant Summary collapse

BUTTON_CLASSES =
['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning',
'btn-danger', 'btn-link'].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(class_) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'app/helpers/url_helper.rb', line 5

def self.included(class_)
  class_.class_eval do
    def button_to(*args, &proc)
      args << nil if args.length < 2
      args << {} if args.length < 3
      button_to_with_bootstrap(*args, &proc)
      super(*args, &proc)
    end
  end
end

Instance Method Details

#button_to_with_bootstrap(name = nil, options = nil, html_options = {}, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/url_helper.rb', line 16

def button_to_with_bootstrap(name = nil, options = nil, html_options = {}, &block)
  html_options[:class] ||= []
  html_options[:class] = [*html_options[:class]]

  # Expand space-separated class strings so that each has its own spot in the class array
  html_options[:class] = html_options[:class].map { |c| c.split }.flatten

  html_options[:class].unshift('btn') unless html_options[:class].include?('btn')
  if html_options[:class].select { |cls| UrlHelper::BUTTON_CLASSES.include?(cls) }.empty?
    html_options[:class] << 'btn-default'
  end
end