Merge pull request #2625 from eyalev/rtl-email

Enable RTL direction in emails.
This commit is contained in:
Robin Ward 2014-08-06 12:46:07 -04:00
commit c55eb67a91
5 changed files with 27 additions and 18 deletions

View File

@ -32,7 +32,7 @@ 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.html_class}"
end
def escape_unicode(javascript)
@ -124,21 +124,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]

View File

@ -198,7 +198,7 @@ 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.html_class }
)
template = "user_notifications.user_#{notification_type}"

23
app/models/rtl.rb Normal file
View File

@ -0,0 +1,23 @@
class RTL
def self.enabled?
site_locale_rtl? || current_user_rtl?
end
def self.current_user_rtl?
SiteSetting.allow_user_locale && current_user.try(:locale).in?(rtl_locales)
end
def self.site_locale_rtl?
!SiteSetting.allow_user_locale && SiteSetting.default_locale.in?(rtl_locales)
end
def self.rtl_locales
%w(he ar)
end
def self.html_class
enabled? ? 'rtl' : ''
end
end

View File

@ -1,4 +1,4 @@
<div id='main'>
<div id='main' class=<%= classes %>>
<% if top.present? %>
<div><%= top %></div>

View File

@ -53,6 +53,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")