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.rb35
1 files changed, 6 insertions, 29 deletions
diff --git a/app/helpers/link_helper.rb b/app/helpers/link_helper.rb
index 39ec495..cb13c8d 100644
--- a/app/helpers/link_helper.rb
+++ b/app/helpers/link_helper.rb
@@ -1,5 +1,5 @@
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,
@@ -8,11 +8,11 @@ module LinkHelper
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? 17 return "" if path.nil?
18 18
@@ -22,9 +22,7 @@ module LinkHelper
22 end 22 end
23 23
24 active_class = active ? {:class => 'active'} : {:class => 'inactive'} 24 active_class = active ? {:class => 'active'} : {:class => 'inactive'}
25
26 html_options = html_options.merge(active_class) 25 html_options = html_options.merge(active_class)
27
28 locale = params[:locale] || I18n.locale 26 locale = params[:locale] || I18n.locale
29 27
30 link_to( 28 link_to(
@@ -39,34 +37,13 @@ module LinkHelper
39 return :class => "selected" 37 return :class => "selected"
40 end 38 end
41 end 39 end
42 40
43 def unlock_link 41 def unlock_link
44 message = "Are you sure you want to unlock?\n" + 42 message = "Are you sure you want to unlock?\n" +
45 "Locked by #{@node.lock_owner.login}\n" + 43 "Locked by #{@node.lock_owner.login}\n" +
46 "Last modified #{@page.updated_at.to_s(:db)}" 44 "Last modified #{@page.updated_at.to_fs(:db)}"
47
48 link_to 'Unlock', safe_path(:unlock_node_path, @node), :method => :put, :data => { :confirm => message }
49 end
50
51 # Rails 6.1 workaround: content_path named helper returns RouteWithParams
52 # when called from within a catch-all glob route request context.
53 # Rails 6.1 workaround: named route helpers return RouteWithParams when called
54 # from within a catch-all glob route request context.
55 # Remove this method when upgrading to Rails 7.0+, where this is fixed.
56 def safe_path(name, *args)
57 Rails.application.routes.url_helpers.send(name, *args)
58 end
59 45
60 def content_path(page_path = nil, options = {}) 46 link_to 'Unlock', unlock_node_path(@node), :method => :put, :data => { :confirm => message }
61 if page_path.is_a?(Hash)
62 options = page_path
63 page_path = options.delete(:page_path)
64 end
65 options[:locale] ||= params[:locale] || I18n.locale
66 Rails.application.routes.url_helpers.content_path(
67 Array(page_path).join("/").sub(/^\//, ""),
68 options
69 )
70 end 47 end
71 48
72end 49end