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
- #activerecord_error_list(errors) ⇒ Object
- #attachment_class_from_content_type(media) ⇒ Object
- #build_menu(menu = Forgeos::Menu, options = { :menu => :menu}, html_options = {}) ⇒ Object
- #current_path?(url, path = request.path.gsub(/\/$/,'')) ⇒ Boolean
- #display_standard_flashes(message = I18n.t(:error), with_tag = true) ⇒ Object
- #find_categories_from_content_type(media) ⇒ Object
- #find_media_type_from_content_type(media) ⇒ Object
- #logged_in? ⇒ Boolean
- #menu_item(tab) ⇒ Object
- #statistics_collector_tag(object) ⇒ Object
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) content_tag :ul do errors.collect do |e, m| content_tag :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 (media) media_class = Media [Video,Pdf,Doc,Picture].each do |klass| media_class = klass if klass.[: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 ( = Forgeos::Menu, = { :menu => :menu}, = {}) = .delete(:menu) .each do |tab| content_for , (tab.dup) end end |
#current_path?(url, path = request.path.gsub(/\/$/,'')) ⇒ 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( = 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 = content_tag :span, , :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 = content_tag :div, :class => 'ui-widget' do content_tag :div, :class => "#{level} ui-corner-all" do content_tag :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) "#{(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) (media).to_s.underscore end |
#logged_in? ⇒ Boolean
3 4 5 |
# File 'app/helpers/forgeos/application_helper.rb', line 3 def logged_in? current_user end |
#menu_item(tab) ⇒ Object
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 (tab) = tab[:html] ? tab[:html].dup : {} tab_name = (tab.delete(:i18n) ? I18n.t(*tab[:title]) : tab[:title]) [:class] = '' unless [:class] urls = tab.delete(:url) if urls.is_a?(Array) urls.each do |url| [:class] += ' current' if current_path?(url) end url = urls.first else url = urls [: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? = [] tab[:children].each do |child| << (child.dup) end link += content_tag(:ul, .join) end content_tag( :li, link, ) 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 |