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.

84 lines
2.0 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(*paths)
  9. paths.any? { |path| 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 locale_direction
  24. if [:ar, :fa, :he].include?(I18n.locale)
  25. 'rtl'
  26. else
  27. 'ltr'
  28. end
  29. end
  30. def favicon_path
  31. env_suffix = Rails.env.production? ? '' : '-dev'
  32. "/favicon#{env_suffix}.ico"
  33. end
  34. def title
  35. Rails.env.production? ? site_title : "#{site_title} (Dev)"
  36. end
  37. def class_for_scope(scope)
  38. 'scope-danger' if DANGEROUS_SCOPES.include?(scope.to_s)
  39. end
  40. def can?(action, record)
  41. return false if record.nil?
  42. policy(record).public_send("#{action}?")
  43. end
  44. def fa_icon(icon, attributes = {})
  45. class_names = attributes[:class]&.split(' ') || []
  46. class_names << 'fa'
  47. class_names += icon.split(' ').map { |cl| "fa-#{cl}" }
  48. content_tag(:i, nil, attributes.merge(class: class_names.join(' ')))
  49. end
  50. def custom_emoji_tag(custom_emoji)
  51. image_tag(custom_emoji.image.url, class: 'emojione', alt: ":#{custom_emoji.shortcode}:")
  52. end
  53. def opengraph(property, content)
  54. tag(:meta, content: content, property: property)
  55. end
  56. def react_component(name, props = {})
  57. content_tag(:div, nil, data: { component: name.to_s.camelcase, props: Oj.dump(props) })
  58. end
  59. def body_classes
  60. output = (@body_classes || '').split(' ')
  61. output << "theme-#{current_theme.parameterize}"
  62. output << 'system-font' if current_account&.user&.setting_system_font_ui
  63. output << (current_account&.user&.setting_reduce_motion ? 'reduce-motion' : 'no-reduce-motion')
  64. output << 'rtl' if locale_direction == 'rtl'
  65. output.reject(&:blank?).join(' ')
  66. end
  67. end