Class: ButtonsFor::Rails::ButtonsForHelper::ButtonsForBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers, FontAwesome::Rails::IconHelper
Defined in:
app/helpers/buttons_for/rails/buttons_for_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ ButtonsForBuilder

Returns a new instance of ButtonsForBuilder.



17
18
19
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 17

def initialize(template)
  @template = template
end

Instance Attribute Details

#output_bufferObject

Returns the value of attribute output_buffer.



15
16
17
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 15

def output_buffer
  @output_buffer
end

#templateObject

Returns the value of attribute template.



15
16
17
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 15

def template
  @template
end

Instance Method Details

#button(text, url, options = {}, &block) ⇒ Object



21
22
23
24
25
26
27
28
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 21

def button(text, url, options = {}, &block)
  icon_options = extract_icon_options!(options)

  link_to label(text, icon_options), url, options.merge(
    class: classes(options),
    title: t(text),
  )
end

#delete(url, options = {}) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 57

def delete(url, options = {})
  options[:label] ||= label(:delete)

  button options[:label], url, options.reverse_merge(
    class: 'btn-danger',
    icon: 'trash-o',
    method: :delete,
    data: {
      confirm: t(:confirm)
    }
  )
end

Raises:

  • (ArgumentError)


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 70

def dropdown(text, options = {}, &block)
  raise ArgumentError, "Missing block" unless block_given?

  icon_options = extract_icon_options!(options)

  (:div, class: "btn-group") do
    concat((:button, label(text), class: "btn btn-default dropdown-toggle", data: {toggle: "dropdown"}, aria: {haspopup: "true", expanded: "false"}) do
      "#{label(text, icon_options)} #{(:span, '', class: "caret")}".html_safe
    end)
    concat((:ul, class: "dropdown-menu", "aria-labelledby" => text) do
      concat template.capture(&block)
    end)
  end
end

#edit(url, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 39

def edit(url, options = {})
  options[:label] ||= label(:edit)

  button options[:label], url, options.reverse_merge(
    class: 'btn-default',
    icon: 'pencil'
  )
end

#export(url, options = {}) ⇒ Object



48
49
50
51
52
53
54
55
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 48

def export(url, options = {})
  options[:label] ||= label(:export)

  button options[:label], url, options.reverse_merge(
    class: 'btn-default',
    icon: 'file-text-o'
  )
end


85
86
87
88
89
90
91
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 85

def link(text, path, options = {})
  options[:title] ||= label(text)

  icon_options = extract_icon_options!(options)

  (:li, link_to(label(text, icon_options), path, options))
end

#new(url, options = {}) ⇒ Object



30
31
32
33
34
35
36
37
# File 'app/helpers/buttons_for/rails/buttons_for_helper.rb', line 30

def new(url, options = {})
  options[:label] ||= label(:new)

  button options[:label], url, options.reverse_merge(
    icon: 'plus',
    class: 'btn-success'
  )
end