summaryrefslogtreecommitdiff
path: root/app/helpers/link_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/helpers/link_helper.rb')
-rw-r--r--app/helpers/link_helper.rb62
1 files changed, 35 insertions, 27 deletions
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb
index 1b20e6d..878e8e4 100644
--- a/app/helpers/link_helper.rb
+++ b/app/helpers/link_helper.rb
@@ -1,54 +1,62 @@
1module LinkHelper 1module LinkHelper
2 2
3 def content_path_helper path_array 3 def content_path_helper path_array
4 url_for( 4 url_for(
5 :controller => :content, 5 :controller => :content,
6 :action => :render_page, 6 :action => :render_page,
7 :locale => params[:locale] || I18n.locale, 7 :locale => (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale),
8 :page_path => path_array 8 :page_path => path_array
9 ) 9 )
10 end 10 end
11 11
12 def content_url_helper path_array 12 def content_url_helper path_array
13 request.protocol + request.host_with_port + content_path_helper(path_array) 13 request.protocol + request.host_with_port + content_path_helper(path_array)
14 end 14 end
15 15
16 def link_to_path title, path, html_options = {} 16 def link_to_path title, path, html_options = {}
17 return "" if path.nil?
18
17 if params[:page_path] 19 if params[:page_path]
18 active = (params[:page_path].join("/") == path.sub(/^\//, "")) 20 page_path = params[:page_path].is_a?(Array) ? params[:page_path].join("/") : params[:page_path]
21 active = (page_path == path.sub(/^\//, ""))
19 end 22 end
20 23
21 active_class = active ? {:class => 'active'} : {:class => 'inactive'} 24 active_class = active ? {:class => 'active'} : {:class => 'inactive'}
22
23 html_options = html_options.merge(active_class) 25 html_options = html_options.merge(active_class)
24 26 locale = (params[:locale] || I18n.locale).to_sym == I18n.default_locale ? nil : (params[:locale] || I18n.locale)
25 params[:locale] ||= I18n.locale 27
26 28 link_to(
27 link_to( 29 title,
28 title, { 30 content_path(path.sub(/^\//, ""), :locale => locale),
29 :controller => :content,
30 :action => :render_page,
31 :locale => params[:locale],
32 :page_path => (path.sub(/^\//, "").split("/") rescue "")
33 },
34 html_options 31 html_options
35 ) 32 )
36 end 33 end
37 34
38 def selected? controller_name 35 def selected? controller_name
39 if params[:controller] == controller_name 36 if params[:controller] == controller_name
40 return :class => "selected" 37 return :class => "selected"
41 end 38 end
42 end 39 end
43 40
44 def unlock_link 41 def unlock_link
45 message = "Are you sure you want to unlock?\n" + 42 message = "Are you sure you want to unlock?\n" \
46 "Locked by #{@node.lock_owner.login}\n" + 43 "Locked by #{@node.lock_owner.login}\n" \
47 "Last modified #{@page.updated_at.to_s(:db)}" 44 "Last modified #{@page.updated_at.to_fs(:db)}"
48 45 button_to 'Unlock', unlock_node_path(@node),
49 link_to( 46 method: :put,
50 'Unlock', unlock_node_path(@node), :method => :put, :confirm => message 47 form: { data: { confirm: message } }
48 end
49
50 def content_path(page_path = nil, options = {})
51 if page_path.is_a?(Hash)
52 options = page_path
53 page_path = options.delete(:page_path)
54 end
55 locale = options[:locale] || params[:locale] || I18n.locale
56 options[:locale] = (locale.to_sym == I18n.default_locale) ? nil : locale
57 Rails.application.routes.url_helpers.content_path(
58 Array(page_path).join("/").sub(/^\//, ""),
59 options
51 ) 60 )
52 end 61 end
53 62end
54end \ No newline at end of file