Module: ApplicationHelper

Defined in:
lib/required/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#admin_buttonsObject



64
65
66
# File 'lib/required/application_helper.rb', line 64

def admin_buttons
  render :partial => 'shared/admin_buttons'
end

#clearObject



56
57
58
# File 'lib/required/application_helper.rb', line 56

def clear
  raw "<br style='clear:both'/>"
end

#date(date, format = :default) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/required/application_helper.rb', line 45

def date(date, format=:default)
  #ref: http://snippets.dzone.com/posts/show/2255
  formats = {
    :default   => "%b %d, %Y",
    :numbers   => "%m-%d-%y",
    :date_time => "%b %d, %Y %I:%M %p",
    :just_time => "%I:%M %p",
  }
  date.strftime(formats[format])
  
end

#display_flash(type = nil) ⇒ Object

——————————LAYOUT————————————-



5
6
7
8
9
10
11
12
13
14
# File 'lib/required/application_helper.rb', line 5

def display_flash (type = nil)
  
  if type.nil?                                                                        #show all flash keys
    html = flash.collect { |type, val| display_flash(type) }
  else
    return flash[type].blank? ? "" : "<p class='flash flash_#{type}'>#{flash[type]}</p> \n"
  end
  
  html
end

#form_errors_helperObject

——————————ADMIN————————————-



61
62
63
# File 'lib/required/application_helper.rb', line 61

def form_errors_helper
  render :partial => 'shared/form_errors'
end


70
71
72
# File 'lib/required/application_helper.rb', line 70

def link_to_destroy
  raw link_to('destroy', @resource, :confirm => 'Are you sure you want to remove this?', :method => :delete, :title => 'remove permanently')
end

#on_if_controller(c) ⇒ Object



20
21
22
23
24
# File 'lib/required/application_helper.rb', line 20

def on_if_controller (c)
  if params[:controller] == c.to_s 
    'on'
  end
end

#on_if_current(path) ⇒ Object



15
16
17
18
19
# File 'lib/required/application_helper.rb', line 15

def on_if_current (path)
  if path == request.fullpath
    'on'
  end
end

#row_toggleObject



42
43
44
# File 'lib/required/application_helper.rb', line 42

def row_toggle
  cycle('a','b')
end

#short_text(st, len = 100) ⇒ Object



39
40
41
# File 'lib/required/application_helper.rb', line 39

def short_text(st, len=100)
  raw truncate( strip_tags( raw(st)), :length=>len)
end

#show_edit_destroy(resource) ⇒ Object



67
68
69
# File 'lib/required/application_helper.rb', line 67

def show_edit_destroy(resource)
  render :partial => 'shared/show_edit_destroy', :locals => {:resource => resource}
end


36
37
38
# File 'lib/required/application_helper.rb', line 36

def titled_link_to (resource)
  link_to(resource.name.titleize, send("#{resource.class.to_s.underscore}_path", resource), :title =>  "View Full #{resource.class.to_s.titleize} Details for #{h resource.name.titleize}")
end

#tr(d) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/required/application_helper.rb', line 25

def tr (d)
# Quick array to table row.
# Takes an array and creates a table row (tr) with each element of the array
# occupying one column (td).
  o = "<tr>\n"
  d.each do |x|
    o << "\t<td>#{x}</td>\n"
  end
  o << "</tr>\n"
  o
end