Sha256: e4248ba9d796768e90c85576327a9e6b0f3e9a7dd9b10169f824fcaac2f714fd
Contents?: true
Size: 947 Bytes
Versions: 3
Compression:
Stored size: 947 Bytes
Contents
# frozen_string_literal: true require 'erb' module Rake module Funnel module Support class TemplateEngine class << self def render(template, filename = nil, binding = nil) render = erb(template) render.filename = filename render.result(binding || top_level_binding) end private def erb(template) template = replace_at_markers(template) trim_mode = '%<>' return ERB.new(template, trim_mode: trim_mode) if RUBY_VERSION >= '2.6' ERB.new(template, nil, trim_mode) end def replace_at_markers(template) tags = /(@\w[\w\.]+\w@)/ (template || '').gsub(tags) do |match| "<%= #{match[1...-1]} %>" end end def top_level_binding TOPLEVEL_BINDING.dup end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
rake-funnel-0.24.0 | lib/rake/funnel/support/template_engine.rb |
rake-funnel-0.23.0 | lib/rake/funnel/support/template_engine.rb |
rake-funnel-0.22.3 | lib/rake/funnel/support/template_engine.rb |