Module: Css3buttons::Helpers::ButtonHelper

Includes:
ActionView::Helpers::FormTagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/css3buttons/helpers/button_helper.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/css3buttons/helpers/button_helper.rb', line 6

def method_missing(method, *args)
  if is_link_method?(method) || is_submit_method?(method) || is_button_method?(method)
    qualifiers = ["primary", "big", "positive", "negative", "pill", "danger", "safe", "button"]
    color_map = {"positive" => "safe", "negative" => "danger"}

    method_qualifiers = strip_method_name(method).split("_") + ["button"]
    method_qualifiers.map! do |qualifier|
      if color_map.has_key?(qualifier)
        qualifier = color_map[qualifier]
      end
      if qualifiers.index(qualifier).nil?
        qualifier = [qualifier, "icon"]
      end
      qualifier
    end.flatten!

    if is_link_method?(method) && block_given?
      link = args.first
      options = args.extract_options!
      link_to(link, options, &Proc.new)
    else
      label = args.first
      link = args[1]
      options = args.extract_options!
      options = add_classes_to_html_options(method_qualifiers, options)

      if is_link_method?(method)
        link_to(label, link, options)
      elsif is_button_method?(method)
         :button, label, { "type" => "submit", "name" => "commit", "value" => "commit" }.merge(options.stringify_keys)
      else
        submit_tag(label, options)
      end
    end
  else
    super
  end
end

Instance Method Details

#button_group(*args, &block) ⇒ Object



54
55
56
57
58
# File 'lib/css3buttons/helpers/button_helper.rb', line 54

def button_group(*args, &block)
  options = args.extract_options!
  group = Css3buttons::ButtonGroup.new(self, options)
  group.render(&block) if block_given?
end

#css3buttons_stylesheets(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/css3buttons/helpers/button_helper.rb', line 45

def css3buttons_stylesheets(options = {})
  options[:include_reset] = true unless options.has_key?(:include_reset)
  if options[:include_reset] == true
    stylesheet_link_tag "css3buttons/reset", "css3buttons/css3-github-buttons"
  else
    stylesheet_link_tag "css3buttons/css3-github-buttons"
  end
end

#minor_button_group(*args, &block) ⇒ Object



60
61
62
63
64
65
# File 'lib/css3buttons/helpers/button_helper.rb', line 60

def minor_button_group(*args, &block)
  options = args.extract_options!
  options[:minor] = true
  group = Css3buttons::ButtonGroup.new(self, options)
  group.render(&block) if block_given?
end