Module: Megatron::ButtonHelper

Defined in:
app/helpers/megatron/button_helper.rb

Instance Method Summary collapse

Instance Method Details

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



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/megatron/button_helper.rb', line 3

def button(text, options = {})
  tag_name = options[:href].present? ? :a : :button
  opts = {
    class: button_classes(options),
    data: options[:data] || {}
  }
  opts[:href] = options[:href] if options[:href]
  opts[:data][:toggle] = options[:toggle] if options[:toggle]
  opts[:data].merge!(options[:dialog].merge(trigger: 'dialog')) if options[:dialog]

   tag_name, opts do
    if options[:icon]
      concat icon(options[:icon])
      concat ' '
    end
    concat text
  end
end

#button_classes(options) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'app/helpers/megatron/button_helper.rb', line 46

def button_classes(options)
  button_type = options[:type] || options[:color]
  classes = button_type.present? ? ["#{button_type.to_s.gsub('_','-')}-btn"] : ["btn"]
  classes << options[:flavor] if options[:flavor]
  classes << options[:class] if options[:class]
  classes << options[:size].to_s.gsub(/xlarge/, 'x-large') if options[:size]
  classes << 'disabled' if options[:disabled]
  classes
end

#destroy_button(text, options = {}) ⇒ Object



34
35
36
# File 'app/helpers/megatron/button_helper.rb', line 34

def destroy_button(text, options = {})
  button(text, options.merge(type: :destroy))
end

#header_button(text, options = {}) ⇒ Object



22
23
24
# File 'app/helpers/megatron/button_helper.rb', line 22

def header_button(text, options = {})
  button(text, {type: :header, flavor: 'btn'}.merge(options))
end

#primary_button(text, options = {}) ⇒ Object



30
31
32
# File 'app/helpers/megatron/button_helper.rb', line 30

def primary_button(text, options = {})
  button(text, options.merge(type: :primary))
end

#primary_destroy_button(text, options = {}) ⇒ Object



38
39
40
# File 'app/helpers/megatron/button_helper.rb', line 38

def primary_destroy_button(text, options={})
  button(text, options.merge(type: :primary_destroy))
end

#primary_header_button(text, options = {}) ⇒ Object



26
27
28
# File 'app/helpers/megatron/button_helper.rb', line 26

def primary_header_button(text, options = {})
  button(text, options.merge(type: :header, flavor: 'primary-btn'))
end

#text_button(text, options = {}) ⇒ Object



42
43
44
# File 'app/helpers/megatron/button_helper.rb', line 42

def text_button(text, options = {})
  button(text, options.merge(type: :text))
end