application_helper.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. module ApplicationHelper
  2. def nav_link(name, path, options = {}, &block)
  3. if glyphicon = options.delete(:glyphicon)
  4. name = "<span class='glyphicon glyphicon-#{glyphicon}'></span> ".html_safe + name
  5. end
  6. content = link_to(name, path, options)
  7. active = current_page?(path)
  8. if block
  9. # Passing a block signifies that the link is a header of a hover
  10. # menu which contains what's in the block.
  11. begin
  12. @nav_in_menu = true
  13. @nav_link_active = active
  14. content += capture(&block)
  15. class_name = "dropdown dropdown-hover #{@nav_link_active ? 'active' : ''}"
  16. ensure
  17. @nav_in_menu = @nav_link_active = false
  18. end
  19. else
  20. # Mark the menu header active if it contains the current page
  21. @nav_link_active ||= active if @nav_in_menu
  22. # An "active" menu item may be an eyesore, hence `!@nav_in_menu &&`.
  23. class_name = !@nav_in_menu && active ? 'active' : ''
  24. end
  25. content_tag :li, content, class: class_name
  26. end
  27. def yes_no(bool)
  28. content_tag :span, bool ? 'Yes' : 'No', class: "label #{bool ? 'label-info' : 'label-default' }"
  29. end
  30. def working(agent)
  31. if agent.disabled?
  32. link_to 'Disabled', agent_path(agent), class: 'label label-warning'
  33. elsif agent.dependencies_missing?
  34. content_tag :span, 'Missing Gems', class: 'label label-danger'
  35. elsif agent.working?
  36. content_tag :span, 'Yes', class: 'label label-success'
  37. else
  38. link_to 'No', agent_path(agent, tab: (agent.recent_error_logs? ? 'logs' : 'details')), class: 'label label-danger'
  39. end
  40. end
  41. def icon_for_service(service)
  42. case service.to_sym
  43. when :twitter, :tumblr, :github
  44. "<i class='fa fa-#{service}'></i>".html_safe
  45. else
  46. "<i class='fa fa-lock'></i>".html_safe
  47. end
  48. end
  49. end