Class: Rtl

Inherits:
Object
  • Object
show all
Defined in:
lib/rtl.rb

Constant Summary collapse

LOCALES =
%w[ar fa_IR he ug ur]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ Rtl

Returns a new instance of Rtl.



8
9
10
# File 'lib/rtl.rb', line 8

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



6
7
8
# File 'lib/rtl.rb', line 6

def user
  @user
end

Instance Method Details

#css_classObject



24
25
26
# File 'lib/rtl.rb', line 24

def css_class
  enabled? ? "rtl" : ""
end

#current_user_rtl?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/rtl.rb', line 16

def current_user_rtl?
  SiteSetting.allow_user_locale && (user&.locale || SiteSetting.default_locale).in?(LOCALES)
end

#enabled?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/rtl.rb', line 12

def enabled?
  site_locale_rtl? || current_user_rtl?
end

#site_locale_rtl?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/rtl.rb', line 20

def site_locale_rtl?
  !SiteSetting.allow_user_locale && SiteSetting.default_locale.in?(LOCALES)
end