Module: UiHelpers::ButtonHelpers

Included in:
ActionViewExtension
Defined in:
lib/ui_helpers/helpers/button.rb

Instance Method Summary collapse

Instance Method Details

#ui_button_tag(content_or_options = nil, options = nil, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ui_helpers/helpers/button.rb', line 3

def ui_button_tag(content_or_options = nil, options = nil, &block)
  if block_given? && content_or_options.is_a?(Hash)
    content, options = capture(&block), content_or_options
  else
    content, options = content_or_options, options
  end
  options ||= {}
  options = options.stringify_keys

  ui_options = options.delete("ui")||{}
  ui_options[:text] = content
  ui_button = UiHelpers::Button.new(self, ui_options)

  options.merge!(ui_button.html_options)

  button_tag(ui_button.content, options)
end

#ui_button_to(name = nil, options = nil, html_options = nil, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/ui_helpers/helpers/button.rb', line 53

def ui_button_to(name = nil, options = nil, html_options = nil, &block)
  # no icon support for input elements
  if block_given?
    content, path, options = capture(&block), name, options
  else
    content, path, options = name, options, html_options
  end
  options ||= {}
  options = options.stringify_keys

  ui_options = options.delete("ui")||{}
  ui_button = UiHelpers::Button.new(self, ui_options)

  options.merge!(ui_button.html_options)

  button_to(content, path, options)
end

#ui_button_to_function(name, function = nil, html_options = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ui_helpers/helpers/button.rb', line 71

def ui_button_to_function(name, function=nil, html_options={})
  content = name
  options = html_options
  options = options.stringify_keys

  ui_options = options.delete("ui")||{}
  ui_button = UiHelpers::Button.new(self, ui_options)

  options.merge!(ui_button.html_options)

  button_to_function(content, function, options)
end


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ui_helpers/helpers/button.rb', line 21

def ui_link_to(name = nil, options = nil, html_options = nil, &block)
  if block_given?
    content, path, options = capture(&block), name, options
  else
    content, path, options = name, options, html_options
  end
  options ||= {}
  options = options.stringify_keys

  ui_options = options.delete("ui")||{}
  ui_options[:text] = content
  ui_button = UiHelpers::Button.new(self, ui_options)

  options.merge!(ui_button.html_options)

  link_to(ui_button.content, path, options)
end


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ui_helpers/helpers/button.rb', line 39

def ui_link_to_function(name, function, html_options={})
  content = name
  options = html_options
  options = options.stringify_keys

  ui_options = options.delete("ui")||{}
  ui_options[:text] = content
  ui_button = UiHelpers::Button.new(self, ui_options)

  options.merge!(ui_button.html_options)

  link_to_function(ui_button.content, function, options)
end

#ui_submit_tag(value = "Save changes", options = {}) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ui_helpers/helpers/button.rb', line 84

def ui_submit_tag(value = "Save changes", options = {})
  content = value
  options = options.stringify_keys

  ui_options = options.delete("ui")||{}
  ui_button = UiHelpers::Button.new(self, ui_options)

  options.merge!(ui_button.html_options)

  submit_tag(content, options)
end