Sha256: 930ef5da8ba96587dd4b933b0de9a8589584f77212d4d62c2f1b08edc4165bd9

Contents?: true

Size: 612 Bytes

Versions: 11

Compression:

Stored size: 612 Bytes

Contents

require 'erb'

module Rake::Funnel::Support
  class TemplateEngine
    class << self
      def render(template, filename = nil, binding = nil)
        render = ERB.new(replace_at_markers(template), nil, '%<>')
        render.filename = filename
        render.result(binding || top_level_binding)
      end

      private
      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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rake-funnel-0.3.2.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.3.1.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.3.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.2.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.1.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.0.6.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.0.5.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.0.4.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.0.3.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.0.2.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.0.1.pre lib/rake/funnel/support/template_engine.rb