initial import boxroom 0.6.2
[boxroom-stian.git] / app / helpers / application_helper.rb
blobf517516de8ea72bcc5e997f0451674ccea6999b3
1 # Global helper methods for views
2 module ApplicationHelper
3   # Replace 'name' with 'username' in a message
4   def name_to_username(msg)
5     return msg.sub('Name', 'Username') if msg
6   end
8   # Returns the path to the given folder.
9   # Link to self determines wether every part of the path links to itself.
10   def path(folder, link_to_self)
11     # the base url for a path is always the same:
12     url = url_for(:controller => 'folder', :action => 'list', :id => nil)
14     # start with the deepest folder and work your way up
15     if link_to_self
16       path = folder.name
17       id = folder.id.to_s
19       # get the folders until folder doesn't have a parent anymore
20       # (you're working your way up now)
21       until folder.parent == nil
22         folder = folder.parent
23         path = folder.name + "/" + path
24       end
26       # Finally, make it a link...
27       path = '<a href="' + url + '/' + id + '">' + h(path) + '</a>'
28     else
29       path = h(folder.name)
31       # get the folders until folder doesn't have a parent anymore
32       # (you're working your way up now)
33       until folder.parent == nil
34         folder = folder.parent
35         path = '<a href="' + url + '/' + folder.id.to_s + '">' + h(folder.name) + '</a> &#187; ' + path
36       end
37     end
39     return path
40   end
41 end