Sha256: cd53a9828d98b7d24055c83e136489f97eb16f3007218da36352fdfcefddbebe

Contents?: true

Size: 720 Bytes

Versions: 29

Compression:

Stored size: 720 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

29 entries across 29 versions & 1 rubygems

Version Path
govspeak-6.7.8 lib/govspeak/template_renderer.rb
govspeak-6.7.7 lib/govspeak/template_renderer.rb
govspeak-6.7.6 lib/govspeak/template_renderer.rb
govspeak-6.7.5 lib/govspeak/template_renderer.rb
govspeak-6.7.4 lib/govspeak/template_renderer.rb
govspeak-6.7.3 lib/govspeak/template_renderer.rb
govspeak-6.7.2 lib/govspeak/template_renderer.rb
govspeak-6.7.1 lib/govspeak/template_renderer.rb
govspeak-6.7.0 lib/govspeak/template_renderer.rb
govspeak-6.6.0 lib/govspeak/template_renderer.rb
govspeak-6.5.11 lib/govspeak/template_renderer.rb
govspeak-6.5.10 lib/govspeak/template_renderer.rb
govspeak-6.5.9 lib/govspeak/template_renderer.rb
govspeak-6.5.8 lib/govspeak/template_renderer.rb
govspeak-6.5.7 lib/govspeak/template_renderer.rb
govspeak-6.5.6 lib/govspeak/template_renderer.rb
govspeak-6.5.5 lib/govspeak/template_renderer.rb
govspeak-6.5.4 lib/govspeak/template_renderer.rb
govspeak-6.5.3 lib/govspeak/template_renderer.rb
govspeak-6.5.2 lib/govspeak/template_renderer.rb