Merge pull request #2707 from eyalev/rtl-email
Enable RTL direction in emails.
This commit is contained in:
commit
8ab9c57ca5
|
@ -32,7 +32,11 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def html_classes
|
||||
"#{mobile_view? ? 'mobile-view' : 'desktop-view'} #{mobile_device? ? 'mobile-device' : 'not-mobile-device'} #{rtl_view? ? 'rtl' : ''}"
|
||||
"#{mobile_view? ? 'mobile-view' : 'desktop-view'} #{mobile_device? ? 'mobile-device' : 'not-mobile-device'} #{rtl_class}"
|
||||
end
|
||||
|
||||
def rtl_class
|
||||
RTL.new(current_user).css_class
|
||||
end
|
||||
|
||||
def escape_unicode(javascript)
|
||||
|
@ -131,21 +135,6 @@ module ApplicationHelper
|
|||
MobileDetection.mobile_device?(request.user_agent)
|
||||
end
|
||||
|
||||
def rtl_view?
|
||||
site_default_rtl? || current_user_rtl?
|
||||
end
|
||||
|
||||
def current_user_rtl?
|
||||
SiteSetting.allow_user_locale && current_user.try(:locale).in?(rtl_locales)
|
||||
end
|
||||
|
||||
def site_default_rtl?
|
||||
!SiteSetting.allow_user_locale && SiteSetting.default_locale.in?(rtl_locales)
|
||||
end
|
||||
|
||||
def rtl_locales
|
||||
%w(he ar)
|
||||
end
|
||||
|
||||
def customization_disabled?
|
||||
controller.class.name.split("::").first == "Admin" || session[:disable_customization]
|
||||
|
|
|
@ -198,7 +198,11 @@ class UserNotifications < ActionMailer::Base
|
|||
html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render(
|
||||
template: 'email/notification',
|
||||
format: :html,
|
||||
locals: { context_posts: context_posts, post: post, top: top ? PrettyText.cook(top).html_safe : nil }
|
||||
locals: { context_posts: context_posts,
|
||||
post: post,
|
||||
top: top ? PrettyText.cook(top).html_safe : nil,
|
||||
classes: RTL.new(user).css_class
|
||||
}
|
||||
)
|
||||
|
||||
template = "user_notifications.user_#{notification_type}"
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
class RTL
|
||||
|
||||
attr_reader :user
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
def enabled?
|
||||
site_locale_rtl? || current_user_rtl?
|
||||
end
|
||||
|
||||
def current_user_rtl?
|
||||
SiteSetting.allow_user_locale && user.try(:locale).in?(rtl_locales)
|
||||
end
|
||||
|
||||
def site_locale_rtl?
|
||||
!SiteSetting.allow_user_locale && SiteSetting.default_locale.in?(rtl_locales)
|
||||
end
|
||||
|
||||
def rtl_locales
|
||||
%w(he ar)
|
||||
end
|
||||
|
||||
def css_class
|
||||
enabled? ? 'rtl' : ''
|
||||
end
|
||||
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
<div id='main'>
|
||||
<div id='main' class=<%= classes %>>
|
||||
|
||||
<% if top.present? %>
|
||||
<div><%= top %></div>
|
||||
|
|
|
@ -58,6 +58,7 @@ module Email
|
|||
style('.user-avatar', 'vertical-align:top;width:55px;')
|
||||
style('.user-avatar img', nil, width: '45', height: '45')
|
||||
style('hr', 'background-color: #ddd; height: 1px; border: 1px;')
|
||||
style('.rtl', 'direction: rtl;')
|
||||
# we can do this but it does not look right
|
||||
# style('#main', 'font-family:"Helvetica Neue", Helvetica, Arial, sans-serif')
|
||||
style('td.body', 'padding-top:5px;', colspan: "2")
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe RTL do
|
||||
|
||||
let(:user) { Fabricate.build(:user) }
|
||||
|
||||
describe '.css_class' do
|
||||
|
||||
context 'user locale is allowed' do
|
||||
before { SiteSetting.stubs(:allow_user_locale).returns(true) }
|
||||
|
||||
context 'user locale is RTL' do
|
||||
before { user.stubs(:locale).returns('he') }
|
||||
|
||||
it 'returns rtl class' do
|
||||
RTL.new(user).css_class.should == 'rtl'
|
||||
end
|
||||
end
|
||||
|
||||
context 'user locale is not RTL' do
|
||||
it 'returns empty class' do
|
||||
RTL.new(user).css_class.should == ''
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'user locale is not allowed' do
|
||||
before { SiteSetting.stubs(:allow_user_locale).returns(false) }
|
||||
|
||||
context 'site default locale is RTL' do
|
||||
before { SiteSetting.stubs(:default_locale).returns('he') }
|
||||
|
||||
it 'returns rtl class' do
|
||||
RTL.new(user).css_class.should == 'rtl'
|
||||
end
|
||||
end
|
||||
|
||||
context 'site default locale is LTR' do
|
||||
before { SiteSetting.stubs(:default_locale).returns('en') }
|
||||
|
||||
context 'user locale is RTL' do
|
||||
before { user.stubs(:locale).returns('he') }
|
||||
|
||||
it 'returns empty class' do
|
||||
RTL.new(user).css_class.should == ''
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue