Sha256: 0d736c42e1ca63e4028c67feddddba1fb1dea52eb4ba4681c9ece9c801a6b6b3
Contents?: true
Size: 722 Bytes
Versions: 20
Compression:
Stored size: 722 Bytes
Contents
module Govspeak class TemplateRenderer attr_reader :template, :locale def initialize(template, locale) @template = template @locale = locale end def render(locals) template_binding = binding locals.each { |k, v| template_binding.local_variable_set(k, v) } erb = ERB.new(File.read(__dir__ + "/../templates/#{template}")) erb.result(template_binding) end def t(*args) options = args.last.is_a?(Hash) ? args.last.dup : {} key = args.shift I18n.t!(key, **options.merge(locale: locale)) end def format_with_html_line_breaks(string) ERB::Util.html_escape(string || "").strip.gsub(/(?:\r?\n)/, "<br/>").html_safe end end end
Version data entries
20 entries across 20 versions & 1 rubygems