Use the dir attribute in dashboard and mailer layouts
We forgot to do so in commit d827768c0. In order to avoid the same
mistake in the future, we're extracting a method to get these
attributes. We're also adding tests, since we didn't have any tests to
check that the `dir` attribute was properly set.
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
<%= attributes -%>
|
||||||
17
app/components/layout/common_html_attributes_component.rb
Normal file
17
app/components/layout/common_html_attributes_component.rb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
class Layout::CommonHTMLAttributesComponent < ApplicationComponent
|
||||||
|
delegate :rtl?, to: :helpers
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def attributes
|
||||||
|
sanitize([dir, lang].compact.join(" "))
|
||||||
|
end
|
||||||
|
|
||||||
|
def dir
|
||||||
|
'dir="rtl"' if rtl?
|
||||||
|
end
|
||||||
|
|
||||||
|
def lang
|
||||||
|
"lang=\"#{I18n.locale}\""
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -9,4 +9,8 @@ module LayoutsHelper
|
|||||||
link_to(text, path, options.merge(title: title))
|
link_to(text, path, options.merge(title: title))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def common_html_attributes
|
||||||
|
render Layout::CommonHTMLAttributesComponent.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
class ApplicationMailer < ActionMailer::Base
|
class ApplicationMailer < ActionMailer::Base
|
||||||
helper :settings
|
helper :application, :layouts, :mailer, :settings
|
||||||
helper :application
|
|
||||||
helper :mailer
|
|
||||||
default from: proc { "#{Setting["mailer_from_name"]} <#{Setting["mailer_from_address"]}>" }
|
default from: proc { "#{Setting["mailer_from_name"]} <#{Setting["mailer_from_address"]}>" }
|
||||||
layout "mailer"
|
layout "mailer"
|
||||||
before_action :set_asset_host
|
before_action :set_asset_host
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html <%= "dir=rtl" if rtl? %> lang="<%= I18n.locale %>">
|
<html <%= common_html_attributes %>>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<%= render "layouts/common_head", default_title: "Admin" %>
|
<%= render "layouts/common_head", default_title: "Admin" %>
|
||||||
<%= content_for :head %>
|
<%= content_for :head %>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html <%= "dir=rtl" if rtl? %> lang="<%= I18n.locale %>" data-current-user-id="<%= current_user&.id %>">
|
<html <%= common_html_attributes %> data-current-user-id="<%= current_user&.id %>">
|
||||||
<head>
|
<head>
|
||||||
<%= render "layouts/common_head", default_title: setting["org_name"] %>
|
<%= render "layouts/common_head", default_title: setting["org_name"] %>
|
||||||
<%= render "layouts/meta_tags" %>
|
<%= render "layouts/meta_tags" %>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="<%= I18n.locale %>" data-current-user-id="<%= current_user&.id %>">
|
<html <%= common_html_attributes %> data-current-user-id="<%= current_user&.id %>">
|
||||||
<head>
|
<head>
|
||||||
<%= render "layouts/common_head", default_title: setting["org_name"] %>
|
<%= render "layouts/common_head", default_title: setting["org_name"] %>
|
||||||
<%= render "layouts/meta_tags" %>
|
<%= render "layouts/meta_tags" %>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html <%= "dir=rtl" if rtl? %> lang="<%= I18n.locale %>">
|
<html <%= common_html_attributes %>>
|
||||||
<head>
|
<head>
|
||||||
<%= render "layouts/common_head", default_title: setting["org_name"] %>
|
<%= render "layouts/common_head", default_title: setting["org_name"] %>
|
||||||
<%= render "layouts/meta_tags" %>
|
<%= render "layouts/meta_tags" %>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
<html lang="<%= I18n.locale %>">
|
<html <%= common_html_attributes %>>
|
||||||
<head>
|
<head>
|
||||||
<title><%= t("mailers.title") %></title>
|
<title><%= t("mailers.title") %></title>
|
||||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html <%= "dir=rtl" if rtl? %> lang="<%= I18n.locale %>">
|
<html <%= common_html_attributes %>>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<%= render "layouts/common_head", default_title: "Management" %>
|
<%= render "layouts/common_head", default_title: "Management" %>
|
||||||
<%= stylesheet_link_tag "print", media: "print" %>
|
<%= stylesheet_link_tag "print", media: "print" %>
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Layout::CommonHTMLAttributesComponent do
|
||||||
|
let(:component) { Layout::CommonHTMLAttributesComponent.new }
|
||||||
|
|
||||||
|
it "includes the default language by default" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page.text).to eq 'lang="en"'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "includes the current language" do
|
||||||
|
I18n.with_locale(:es) { render_inline component }
|
||||||
|
|
||||||
|
expect(page.text).to eq 'lang="es"'
|
||||||
|
end
|
||||||
|
|
||||||
|
context "RTL languages" do
|
||||||
|
let!(:default_enforce) { I18n.enforce_available_locales }
|
||||||
|
|
||||||
|
before do
|
||||||
|
I18n.enforce_available_locales = false
|
||||||
|
allow(I18n).to receive(:available_locales).and_return(%i[ar en es])
|
||||||
|
end
|
||||||
|
|
||||||
|
after { I18n.enforce_available_locales = default_enforce }
|
||||||
|
|
||||||
|
it "includes the dir attribute" do
|
||||||
|
I18n.with_locale(:ar) { render_inline component }
|
||||||
|
|
||||||
|
expect(page.text).to eq 'dir="rtl" lang="ar"'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user