-require 'htmlentities'
+require "htmlentities"
module TitleHelper
- @@coder = HTMLEntities.new
+ def self.coder
+ @coder ||= HTMLEntities.new
+ end
- def set_title(title = false)
+ def set_title(title = nil)
if title
- @title = @@coder.decode(title.gsub("<bdi>", "\u202a").gsub("</bdi>", "\u202c"))
- response.headers["X-Page-Title"] = @title + ' | ' + t('layouts.project_name.title')
+ @title = TitleHelper.coder.decode(title.gsub("<bdi>", "\u202a").gsub("</bdi>", "\u202c"))
- response.headers["X-Page-Title"] = ERB::Util.u(t("layouts.project_name.title") + " | " + @title)
++ response.headers["X-Page-Title"] = ERB::Util.u(@title + " | " + t("layouts.project_name.title"))
else
@title = title
- response.headers["X-Page-Title"] = t('layouts.project_name.title')
+ response.headers["X-Page-Title"] = ERB::Util.u(t("layouts.project_name.title"))
end
end
end
assert_nil @title
set_title("Test Title")
- assert_equal "OpenStreetMap%20%7C%20Test%20Title", response.header["X-Page-Title"]
- assert_equal "Test Title | OpenStreetMap", response.header["X-Page-Title"]
++ assert_equal "Test%20Title%20%7C%20OpenStreetMap", response.header["X-Page-Title"]
assert_equal "Test Title", @title
set_title("Test & Title")
- assert_equal "OpenStreetMap%20%7C%20Test%20%26%20Title", response.header["X-Page-Title"]
- assert_equal "Test & Title | OpenStreetMap", response.header["X-Page-Title"]
++ assert_equal "Test%20%26%20Title%20%7C%20OpenStreetMap", response.header["X-Page-Title"]
assert_equal "Test & Title", @title
- assert_equal "OpenStreetMap%20%7C%20T%C3%A9st%20%26%20T%C3%AFtl%C3%A8", response.header["X-Page-Title"]
+
+ set_title("Tést & Tïtlè")
++ assert_equal "T%C3%A9st%20%26%20T%C3%AFtl%C3%A8%20%7C%20OpenStreetMap", response.header["X-Page-Title"]
+ assert_equal "Tést & Tïtlè", @title
end
end