ref: master
app/helpers/buttons_helper.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
module ButtonsHelper def button_bar(options = {}, &block) options[:class] ||= '' options[:class] << ' button-bar' content_tag :div, options do [ capture(&block).to_s, tag(:br, style: 'clear: left;'), ].safe_join end end def button(type, label, url, html_options = {}) html_options ||= {} the_class = 'with-text' if html_options.has_key?(:class) the_class << ' ' << html_options[:class] end button_without_text type, label, url, html_options.merge(:class => the_class) end def button_without_text(type, label, url, html_options = {}) the_class = "button icon-#{type}" if html_options.has_key?(:class) the_class << ' ' << html_options[:class] end the_title = html_options[:title] || label if html_options[:disabled] content_tag('a', ' '.html_safe+content_tag('span', label), html_options.merge(:class => the_class, :title => the_title)) else link_to(' '.html_safe+content_tag('span', label), url, html_options.merge(:class => the_class, :title => the_title)) end end def button_to_function(type, label, js_code, html_options = {}, &block) html_options[:class] = "button with-text" unless html_options[:class] html_options[:class] << " icon-#{type}" link_to_function(label, js_code, html_options, &block) end def button_to_function_without_text(type, label, js_code, html_options = {}, &block) html_options[:class] = "" unless html_options[:class] html_options[:class] << " button icon-#{type}" link_to_function(content_tag('span', label), js_code, html_options, &block) end def button_to_remote(type, label, options, html_options = {}) html_options[:class] = "button with-text" unless html_options[:class] html_options[:class] << " icon-#{type}" link_to_remote(label, options, html_options) end def button_to_remote_without_text(type, label, options, html_options = {}) html_options[:class] = "" unless html_options[:class] html_options[:class] << " button icon-#{type}" link_to_remote(content_tag('span', label), options, html_options.merge(:title => label)) end end |