The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

71 regels
1.6 KiB

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