Module: IHelpers

Defined in:
lib/i_helpers.rb,
lib/i_helpers/active_record/validations.rb

Defined Under Namespace

Modules: ActiveRecord

Instance Method Summary collapse

Instance Method Details

#discard_flashObject



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_tagObject



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 << (:div, flash[:notice], {:id => "flash_notice", :style => notice_style})
  r << (: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)
  options = files.extract_options!
  options.reverse_merge! :placement => :head
  content_for(options[:placement]) { javascript_include_tag(*files) }
end


71
72
73
74
75
76
# File 'lib/i_helpers.rb', line 71

def link_with_icon_to(options = {})
  r = link_with_icon(options)
  options[:link_options].reverse_merge!(:class => "with_icon")
  r = link_to(r, options[:url], options[:link_options]) if !options[:disabled]
  r
end


78
79
80
81
82
83
84
85
86
87
# File 'lib/i_helpers.rb', line 78

def link_with_icon_to_remote(options = {})
  r = link_with_icon(options)
  options.reverse_merge!(:link_html_options => {})
  options.reverse_merge!(:method => :post)
  options[:link_options].reverse_merge!({:method => options[:method]})
  options[:link_html_options].reverse_merge!(:class => "with_icon")
  r = link_to_remote(r, {:url => options[:url]}.merge(options[:link_options]),
    options[:link_html_options]) if !options[: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, options = {})
  options.reverse_merge! :class => "icon"
  prefix = IHelpers.small_icons_location
  if options[:grayed_out]
    options.delete :grayed_out
    prefix += "grayed_out/"
  end
  image_tag("#{prefix}#{icon}.png" , options)
end

#stylesheet(*files) ⇒ Object



29
30
31
32
33
# File 'lib/i_helpers.rb', line 29

def stylesheet(*files)
  options = files.extract_options!
  options.reverse_merge! :placement => :head
  content_for(options[: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)
  options = args.extract_options! || {}
  
  options.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
      options[:class] = [options[:class], 'error'].compact.join(' ') if options[:error]
      return (:h1, [options[:header], in_place_title, options[:trailer]].compact.join(' '), options.except(:error, :header, :trailer))
    end
  else
    sitename = options[: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_flashObject



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