Module: IHelpers
- Defined in:
- lib/i_helpers.rb,
lib/i_helpers/active_record/validations.rb
Defined Under Namespace
Modules: ActiveRecord
Instance Method Summary collapse
- #discard_flash ⇒ Object
- #flash_tag ⇒ Object
- #focus_on(id) ⇒ Object
- #javascript(*files) ⇒ Object
- #link_with_icon_to(options = {}) ⇒ Object
- #link_with_icon_to_remote(options = {}) ⇒ Object
- #n2br(str) ⇒ Object
- #small_icon(icon, options = {}) ⇒ Object
- #stylesheet(*files) ⇒ Object
-
#title(*args) ⇒ Object
New version inspired by title_helper: github.com/DefV/title_helper/tree/master.
- #update_flash ⇒ Object
Instance Method Details
#discard_flash ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/i_helpers.rb', line 114 def discard_flash r = "" update_page do |page| r << (page.replace_html :flash_notice, nil) r << (page.hide :flash_notice) flash.discard :notice if flash[:notice] r << (page.replace_html :flash_error, nil) r << (page.hide :flash_error) flash.discard :error if flash[:error] end r end |
#flash_tag ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/i_helpers.rb', line 89 def flash_tag r = "" notice_style = "display: none;" if !flash[:notice] error_style = "display: none;" if !flash[:error] r << content_tag(:div, flash[:notice], {:id => "flash_notice", :style => notice_style}) r << content_tag(:div, flash[:error], {:id => "flash_error", :style => error_style}) end |
#focus_on(id) ⇒ Object
15 16 17 |
# File 'lib/i_helpers.rb', line 15 def focus_on id javascript_tag "$('#{id}').focus()"; end |
#javascript(*files) ⇒ Object
23 24 25 26 27 |
# File 'lib/i_helpers.rb', line 23 def javascript(*files) = files. .reverse_merge! :placement => :head content_for([:placement]) { javascript_include_tag(*files) } end |
#link_with_icon_to(options = {}) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/i_helpers.rb', line 71 def link_with_icon_to( = {}) r = link_with_icon() [:link_options].reverse_merge!(:class => "with_icon") r = link_to(r, [:url], [:link_options]) if ![:disabled] r end |
#link_with_icon_to_remote(options = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/i_helpers.rb', line 78 def link_with_icon_to_remote( = {}) r = link_with_icon() .reverse_merge!(:link_html_options => {}) .reverse_merge!(:method => :post) [:link_options].reverse_merge!({:method => [:method]}) [:link_html_options].reverse_merge!(:class => "with_icon") r = link_to_remote(r, {:url => [:url]}.merge([:link_options]), [:link_html_options]) if ![:disabled] r end |
#n2br(str) ⇒ Object
19 20 21 |
# File 'lib/i_helpers.rb', line 19 def n2br(str) str.gsub("\n", "<br />") end |
#small_icon(icon, options = {}) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/i_helpers.rb', line 61 def small_icon(icon, = {}) .reverse_merge! :class => "icon" prefix = IHelpers.small_icons_location if [:grayed_out] .delete :grayed_out prefix += "grayed_out/" end image_tag("#{prefix}#{icon}.png" , ) end |
#stylesheet(*files) ⇒ Object
29 30 31 32 33 |
# File 'lib/i_helpers.rb', line 29 def stylesheet(*files) = files. .reverse_merge! :placement => :head content_for([:placement]) { stylesheet_link_tag(*files) } end |
#title(*args) ⇒ Object
New version inspired by title_helper: github.com/DefV/title_helper/tree/master
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/i_helpers.rb', line 37 def title(*args) = args. || {} .delete([:page, :bar]) # for (at least a bit of) backwards compatibility if args.length > 0 in_place_title = args[0] @title = in_place_title.gsub(/<\/?[^>]*>/, "") if IHelpers.title_print_in_place [:class] = [[:class], 'error'].compact.join(' ') if [:error] return content_tag(:h1, [[:header], in_place_title, [:trailer]].compact.join(' '), .except(:error, :header, :trailer)) end else sitename = [:site_name] if @title && !sitename.blank? return IHelpers.title_format.gsub('$title', h(@title)).gsub('$sitename', h(sitename)) elsif @title && sitename.blank? return h(@title) else return "#{sitename}" end end end |
#update_flash ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/i_helpers.rb', line 97 def update_flash r = "" update_page do |page| if flash[:notice] r << (page.replace_html :flash_notice, flash[:notice]) r << (page.show :flash_notice) flash.discard :notice end if flash[:error] r << (page.replace_html :flash_error, flash[:error]) r << (page.show :flash_error) flash.discard :error end end r end |