Module: Forgeos::ApplicationHelper

Defined in:
app/helpers/forgeos/application_helper.rb

Overview

Methods added to this helper will be available to all templates in the application.

Instance Method Summary collapse

Instance Method Details

#activerecord_error_list(errors) ⇒ Object



51
52
53
54
55
56
57
# File 'app/helpers/forgeos/application_helper.rb', line 51

def activerecord_error_list(errors)
   :ul do
    errors.collect do |e, m|
       :li, "#{e.capitalize unless e == "base"} #{m}"
    end
  end
end

#attachment_class_from_content_type(media) ⇒ Object



95
96
97
98
99
100
101
# File 'app/helpers/forgeos/application_helper.rb', line 95

def attachment_class_from_content_type(media)
  media_class = Media
  [Video,Pdf,Doc,Picture].each do |klass|
    media_class = klass if klass.attachment_options[:content_type].include?(media.content_type)
  end
  media_class
end

#build_menu(menu = Forgeos::Menu, options = { :menu => :menu}, html_options = {}) ⇒ Object



7
8
9
10
11
12
# File 'app/helpers/forgeos/application_helper.rb', line 7

def build_menu(menu = Forgeos::Menu,options = { :menu => :menu}, html_options = {})
  menu_name = options.delete(:menu)
  menu.each do |tab|
    content_for menu_name, menu_item(tab.dup)
  end
end

#current_path?(url, path = request.path.gsub(/\/$/,'')) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'app/helpers/forgeos/application_helper.rb', line 14

def current_path?(url,path = request.path.gsub(/\/$/,''))
  (url_for(url) != '/' || path == '/') && (url_for(url) != '/admin' || path == '/admin') && path.include?(url_for(url))
end

#display_standard_flashes(message = I18n.t(:error), with_tag = true) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/helpers/forgeos/application_helper.rb', line 59

def display_standard_flashes(message = I18n.t(:error), with_tag = true)
  if !flash[:notice].nil? && !flash[:notice].blank?
    flash_to_display, level = flash[:notice], 'ui-state-highlight'
    flash[:notice] = nil
  elsif !flash[:warning].nil? && !flash[:warning].blank?
    flash_to_display, level = flash[:warning], 'ui-state-error'
    flash[:warning] = nil
  elsif !flash[:error].nil? && !flash[:error].blank?
    level = 'ui-state-error'
    if flash[:error].instance_of? ActiveRecord::Errors
      flash_to_display =  :span, message, :class => 'ico close'
      flash_to_display << activerecord_error_list(flash[:error])
    else
      flash_to_display = flash[:error]
    end
    flash[:error] = nil
  else
    return
  end

  content =  :div, :class => 'ui-widget' do
     :div, :class => "#{level} ui-corner-all" do
       :p, flash_to_display, :style => 'text-align : center'
    end
  end

  script = render(:update) do |page|
    page.replace_html('display_standard_flashes', content)
    page.visual_effect(:slide_down, 'display_standard_flashes')
    page.delay(10) do
      page.visual_effect(:slide_up,'display_standard_flashes')
    end
  end
  return with_tag ? javascript_tag(script) : script
end

#find_categories_from_content_type(media) ⇒ Object



103
104
105
# File 'app/helpers/forgeos/application_helper.rb', line 103

def find_categories_from_content_type(media)
  "#{attachment_class_from_content_type(media)}Category".constantize.find_all_by_parent_id(nil)
end

#find_media_type_from_content_type(media) ⇒ Object



107
108
109
# File 'app/helpers/forgeos/application_helper.rb', line 107

def find_media_type_from_content_type(media)
  attachment_class_from_content_type(media).to_s.underscore
end

#logged_in?Boolean

Returns:

  • (Boolean)


3
4
5
# File 'app/helpers/forgeos/application_helper.rb', line 3

def logged_in?
  current_user
end


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
# File 'app/helpers/forgeos/application_helper.rb', line 18

def menu_item(tab)
  html_options = tab[:html] ? tab[:html].dup : {}
  tab_name = (tab.delete(:i18n) ? I18n.t(*tab[:title]) : tab[:title])
  html_options[:class] = '' unless html_options[:class]
  urls = tab.delete(:url)

  if urls.is_a?(Array)
    urls.each do |url|
      html_options[:class] += ' current' if current_path?(url)
    end
    url = urls.first
  else
    url = urls
    html_options[:class] += ' current' if current_path?(url)
  end

  if helper = tab.delete(:helper)
      link = self.send(helper[:method],tab_name)
  else
      link = link_to(tab_name.capitalize, url)
  end

  if tab[:children] && !tab[:children].empty?
    menu = []
    tab[:children].each do |child|
      menu << menu_item(child.dup)
    end
    link += (:ul, menu.join)
  end

  ( :li, link, html_options)
end

#statistics_collector_tag(object) ⇒ Object



111
112
113
# File 'app/helpers/forgeos/application_helper.rb', line 111

def statistics_collector_tag(object)
  javascript_include_tag(forgeos_core.statistics_collector_path(:type => object.class.to_s.underscore, :id => object.id))
end