summaryrefslogtreecommitdiff
path: root/app/helpers/link_helper.rb
blob: e5fc63265c4835fe2368fcef57e0e27b714b0ce9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module LinkHelper
  
  def content_path_helper path_array
    url_for(
      :controller => :content,
      :action => :render_page,
      :locale => params[:locale] || I18n.locale,
      :page_path => path_array
    )
  end
  
  def content_url_helper path_array
    request.protocol + request.host_with_port + content_path_helper(path_array)
  end
  
  def link_to_path title, path, html_options = {}
    if params[:page_path]
      active = (params[:page_path].join("/") == path.sub(/^\//, ""))
    end
    
    params[:locale] ||= I18n.locale
    
    link_to( 
      title, {
        :controller => :content,
        :action => :render_page,
        :locale => params[:locale],
        :page_path => path.sub(/^\//, "").split("/")
      },
      active ? {:class => 'active'} : {:class => 'inactive'}
    )
  end
  
  def selected? controller_name
    if params[:controller] == controller_name
      return :class => "selected"
    end
  end
end