]> git.openstreetmap.org Git - rails.git/blobdiff - app/helpers/title_helper.rb
Use Hash#dig to simplify code
[rails.git] / app / helpers / title_helper.rb
index a1a2125a173f81a72f2b53dcdccecdb3b9322e3f..ebe5c3a2631ca27f314d64835c400d35daa25812 100644 (file)
@@ -1,15 +1,17 @@
-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"] = t('layouts.project_name.title') + ' | ' + @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)
     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