Module: ApplicationHelper

Defined in:
lib/forge/app/helpers/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#first_image(obj, options = {}) ⇒ Object

eg. first_image(@product)



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/forge/app/helpers/application_helper.rb', line 57

def first_image(obj, options = {})
  opts = {
    :collection => :images,
    :method => :image,
    :style => :thumbnail,
    :default => image_path('noimage.jpg')
  }.merge(options.symbolize_keys!)

  image = obj.send(opts[:collection]).first
  image ? image.send(opts[:method]).url(opts[:style]) : opts[:default]
end

#flash_messagesObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/forge/app/helpers/application_helper.rb', line 7

def flash_messages
  messages = []
  %w(notice warning error alert).each do |msg|
    unless flash[msg.to_sym].blank?
      content = (:p, flash[msg.to_sym])
      messages << (:div, content, :class => "flash-msg flash-#{msg}")
    end
  end
  messages.join('').html_safe
end

#gravatar_for(object) ⇒ Object



28
29
30
# File 'lib/forge/app/helpers/application_helper.rb', line 28

def gravatar_for(object)
  gravatar_image_tag(object.email)
end

#html(options = { }, &blk) ⇒ Object



69
70
71
72
73
74
75
76
77
# File 'lib/forge/app/helpers/application_helper.rb', line 69

def html(options = { }, &blk)
  options.recursive_symbolize_keys!

  open = h5bp_opening_tag(options[:ie_versions])
  body = capture_haml(&blk)
  close = "</html>".html_safe

  open + body + close
end

#jquery_for_environmentObject



2
3
4
5
# File 'lib/forge/app/helpers/application_helper.rb', line 2

def jquery_for_environment
  path = ENV['RAILS_ENV'] == "production" ? 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js' : 'jquery'
  javascript_include_tag path
end


18
19
20
21
22
23
24
25
# File 'lib/forge/app/helpers/application_helper.rb', line 18

def menu_item(title, link, options = {})
  klass = ""
  #set the link class to active if it matches the current link or any of the alternate supplied links
  options[:alt_links].each { |a| klass = request.fullpath.match(a) ? "active" : "" unless klass == "active" } if options[:alt_links].is_a?(Array)
  klass = "active" if link == request.fullpath
  klass += " #{options[:class]}" unless options[:class].blank?
  return link_to(title, link, :class => klass)
end

#seo_meta_tagsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/forge/app/helpers/application_helper.rb', line 42

def seo_meta_tags
  obj = instance_variable_get("@#{params[:controller].singularize}")
  tags = []
  if obj
    if obj.respond_to?(:seo_keywords) && !obj.seo_keywords.blank?
      tags << tag(:meta, {:name => "keywords", :content => obj.seo_keywords })
    end
    if obj.respond_to?(:seo_description) && !obj.seo_description.blank?
      tags << tag(:meta, {:name => "description", :content => obj.seo_description})
    end
  end
  return tags.join
end

#table_row(*args) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/forge/app/helpers/application_helper.rb', line 32

def table_row(*args)
  html = "<tr>"
  args.each_with_index do |cell, i|
    html += "<td class='cell-#{i+1}'>#{cell}</td>"
  end
  html += "</tr>\n"

  html.html_safe
end