Class: Caisson::Helpers::Form::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/caisson/helpers/form/button.rb

Instance Method Summary collapse

Constructor Details

#initialize(core) ⇒ Button

************************************************************************************* CONSTRUCTOR *************************************************************************************



9
10
11
# File 'lib/caisson/helpers/form/button.rb', line 9

def initialize(core)
  @core = core
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object (private)



60
# File 'lib/caisson/helpers/form/button.rb', line 60

def method_missing(*args, &block) return @core.send(*args, &block) end

Instance Method Details

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

************************************************************************************* PUBLIC INSTANCE METHODS *************************************************************************************



17
18
19
20
21
22
23
24
25
# File 'lib/caisson/helpers/form/button.rb', line 17

def build(text, options={})
  options.reverse_merge!(class: '', confirm: nil, default: true, disabled: false, url: nil)

  if options[:url]
    return link(text, options.delete(:url), options)
  else
    return button(text, options)
  end
end

#build_button_to(text, url, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/caisson/helpers/form/button.rb', line 27

def build_button_to(text, url, options={})
  options.reverse_merge!(class: '', confirm: nil, disabled: false, method: 'get', url: nil, vars: {})

  vars = options.delete(:vars)

  return form_tag(url, method: options[:method], class: "button_to") do
    (vars.map{ |k,v| hidden_field_tag(k, v) }.join("\n") + button(text, options)).html_safe
  end
end