Sha256: d1dd8b9024893be95feb49c655313c655da6ed524164d31af2569763ba8abb95

Contents?: true

Size: 694 Bytes

Versions: 18

Compression:

Stored size: 694 Bytes

Contents

require 'erb'

module Rake
  module Funnel
    module 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
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rake-funnel-0.18.0 lib/rake/funnel/support/template_engine.rb
rake-funnel-0.17.0 lib/rake/funnel/support/template_engine.rb
rake-funnel-0.16.1 lib/rake/funnel/support/template_engine.rb
rake-funnel-0.16.0 lib/rake/funnel/support/template_engine.rb
rake-funnel-0.15.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.14.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.13.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.12.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.11.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.10.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.9.1.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.9.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.8.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.7.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.6.1.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.6.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.5.0.pre lib/rake/funnel/support/template_engine.rb
rake-funnel-0.4.0.pre lib/rake/funnel/support/template_engine.rb