Module: Skyline::ButtonHelper

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

Instance Method Summary collapse

Instance Method Details

#button_text(key) ⇒ Object

Translates the key if it’s a symbol otherwise just places key –



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

def button_text(key)
  key.kind_of?(Symbol) ? t(key, :scope => :buttons) : key
end


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

def menu_button(title, options={}, &block)
  options.reverse_merge! :id => Guid.new
  
  contents = capture(&block)
  
  concat <<-EOS
  <dl class="menubutton" id="#{options[:id]}">
    <dt>
      <span class="label">#{title}</span>
      <a class="toggle" href="#"><span><span>down</span></span></a>
    </dt>
    <dd>
      #{contents}
    </dd>
  </dl>
  <script type="text/javascript" charset="utf-8">
    new Skyline.MenuButton('#{options[:id]}')
  </script>
  EOS
end

#submit_button(label, options = {}) ⇒ Object

Places a <button type=“submit”>..</button> tag

Parameters

src

The location of the image relative to the locale directory

options

Options to pass through to content_tag

Options

:value

If value is a symbol, it will be translated in scope buttons



39
40
41
42
43
44
# File 'app/helpers/skyline/button_helper.rb', line 39

def submit_button(label,options={})
  convert_boolean_attributes!(options, %w( disabled ))
  
  options.reverse_merge! :type => "submit"
  ("button", button_text(label) ,options)
end

#submit_button_to(label, options = {}, html_options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/skyline/button_helper.rb', line 46

def submit_button_to(label,options={},html_options={})
  
  html_options = html_options.stringify_keys
  disabled = html_options[:disabled]
  convert_boolean_attributes!(html_options, %w( disabled ))
  
  method_tag = ''
  if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
    method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
  end
  
  form_method = method.to_s == 'get' ? 'get' : 'post'
  
  request_token_tag = ''
  if form_method == 'post' && protect_against_forgery?
    request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
  end
  
  if confirm = html_options.delete("confirm")
    html_options["onclick"] = "return #{confirm_javascript_function(confirm)};"
  end
  
  url = options.is_a?(String) ? options : self.url_for(options)
  name ||= url
  
  html_options.reverse_merge! :type => "submit"
  
  "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +
    method_tag + ("button", button_text(label) ,html_options) + request_token_tag + "</div></form>"    
end