You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
1.8 KiB

8 years ago
8 years ago
  1. # frozen_string_literal: true
  2. module ApplicationHelper
  3. DANGEROUS_SCOPES = %w(
  4. read
  5. write
  6. follow
  7. ).freeze
  8. def active_nav_class(path)
  9. current_page?(path) ? 'active' : ''
  10. end
  11. def active_link_to(label, path, **options)
  12. link_to label, path, options.merge(class: active_nav_class(path))
  13. end
  14. def show_landing_strip?
  15. !user_signed_in? && !single_user_mode?
  16. end
  17. def open_registrations?
  18. Setting.open_registrations
  19. end
  20. def open_deletion?
  21. Setting.open_deletion
  22. end
  23. def add_rtl_body_class(other_classes)
  24. other_classes = "#{other_classes} rtl" if locale_direction == 'rtl'
  25. other_classes
  26. end
  27. def locale_direction
  28. if [:ar, :fa, :he].include?(I18n.locale)
  29. 'rtl'
  30. else
  31. 'ltr'
  32. end
  33. end
  34. def favicon_path
  35. env_suffix = Rails.env.production? ? '' : '-dev'
  36. "/favicon#{env_suffix}.ico"
  37. end
  38. def title
  39. Rails.env.production? ? site_title : "#{site_title} (Dev)"
  40. end
  41. def class_for_scope(scope)
  42. 'scope-danger' if DANGEROUS_SCOPES.include?(scope.to_s)
  43. end
  44. def can?(action, record)
  45. return false if record.nil?
  46. policy(record).public_send("#{action}?")
  47. end
  48. def fa_icon(icon, attributes = {})
  49. class_names = attributes[:class]&.split(' ') || []
  50. class_names << 'fa'
  51. class_names += icon.split(' ').map { |cl| "fa-#{cl}" }
  52. content_tag(:i, nil, attributes.merge(class: class_names.join(' ')))
  53. end
  54. def custom_emoji_tag(custom_emoji)
  55. image_tag(custom_emoji.image.url, class: 'emojione', alt: ":#{custom_emoji.shortcode}:")
  56. end
  57. def opengraph(property, content)
  58. tag(:meta, content: content, property: property)
  59. end
  60. def react_component(name, props = {})
  61. content_tag(:div, nil, data: { component: name.to_s.camelcase, props: Oj.dump(props) })
  62. end
  63. end