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

Version Path
govspeak-8.3.4 lib/govspeak/template_renderer.rb
govspeak-8.3.3 lib/govspeak/template_renderer.rb
govspeak-8.3.2 lib/govspeak/template_renderer.rb
govspeak-8.3.1 lib/govspeak/template_renderer.rb
govspeak-8.3.0 lib/govspeak/template_renderer.rb
govspeak-8.2.1 lib/govspeak/template_renderer.rb
govspeak-8.2.0 lib/govspeak/template_renderer.rb
govspeak-8.1.0 lib/govspeak/template_renderer.rb
govspeak-8.0.1 lib/govspeak/template_renderer.rb
govspeak-8.0.0 lib/govspeak/template_renderer.rb
govspeak-7.1.1 lib/govspeak/template_renderer.rb
govspeak-7.1.0 lib/govspeak/template_renderer.rb
govspeak-7.0.2 lib/govspeak/template_renderer.rb
govspeak-7.0.1 lib/govspeak/template_renderer.rb
govspeak-7.0.0 lib/govspeak/template_renderer.rb
govspeak-6.8.4 lib/govspeak/template_renderer.rb
govspeak-6.8.3 lib/govspeak/template_renderer.rb
govspeak-6.8.2 lib/govspeak/template_renderer.rb
govspeak-6.8.1 lib/govspeak/template_renderer.rb
govspeak-6.8.0 lib/govspeak/template_renderer.rb