summaryrefslogtreecommitdiff
path: root/app/helpers/navigation_helper.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2014-05-16 08:42:36 +0200
committerAzul <azul@leap.se>2014-05-16 08:42:36 +0200
commit8fbbb8717f0578536b97c2dc0883c632f120e976 (patch)
tree17aeb2b48ada703ac916a9a65fbf3c75a5dadb86 /app/helpers/navigation_helper.rb
parent81555ec6244ed76f92e3629880f68104b8705817 (diff)
parenta4f7a410c536d88c91c834cab6ee950c71005ddd (diff)
Merge remote-tracking branch 'origin/develop'
Conflicts: app/assets/javascripts/srp test/nagios/soledad_sync.py test/nagios/webapp_login.py
Diffstat (limited to 'app/helpers/navigation_helper.rb')
-rw-r--r--app/helpers/navigation_helper.rb82
1 files changed, 82 insertions, 0 deletions
diff --git a/app/helpers/navigation_helper.rb b/app/helpers/navigation_helper.rb
new file mode 100644
index 0000000..19cb934
--- /dev/null
+++ b/app/helpers/navigation_helper.rb
@@ -0,0 +1,82 @@
+module NavigationHelper
+
+ #
+ # used to create a side navigation link.
+ #
+ # Signature is the same as link_to, except it accepts an :active value in the html_options
+ #
+ def link_to_navigation(*args)
+ if args.last.is_a? Hash
+ html_options = args.pop.dup
+ active_class = html_options.delete(:active) ? 'active' : nil
+ html_options[:class] = [html_options[:class], active_class].join(' ')
+ args << html_options
+ else
+ active_class = nil
+ end
+ content_tag :li, :class => active_class do
+ link_to(*args)
+ end
+ end
+
+ #
+ # returns true if params[:action] matches one of the args.
+ #
+ def action?(*actions)
+ actions.detect do |action|
+ if action.is_a? String
+ action == action_string
+ elsif action.is_a? Symbol
+ if action == :none
+ action_string == nil
+ else
+ action == action_symbol
+ end
+ end
+ end
+ end
+
+ #
+ # returns true if params[:controller] matches one of the args.
+ #
+ # for example:
+ # controller?(:me, :home)
+ # controller?('groups/') <-- matches any controller in namespace 'groups'
+ #
+ def controller?(*controllers)
+ controllers.each do |cntr|
+ if cntr.is_a? String
+ if cntr.ends_with?('/')
+ return true if controller_string.starts_with?(cntr.chop)
+ end
+ return true if cntr == controller_string
+ elsif cntr.is_a? Symbol
+ return true if cntr == controller_symbol
+ end
+ end
+ return false
+ end
+
+ private
+
+ def controller_string
+ @controller_string ||= params[:controller].to_s.gsub(/^\//, '')
+ end
+
+ def controller_symbol
+ @controller_symbol ||= params[:controller].gsub(/^\//,'').gsub('/','_').to_sym
+ end
+
+ def action_string
+ params[:action]
+ end
+
+ def action_symbol
+ @action_symbol ||= if params[:action].present?
+ params[:action].to_sym
+ else
+ nil
+ end
+ end
+
+end