Sha256: 3351e8478bd4ba62128ae178cbdd2dc093c52000877531e9a4de9b3ef1843db5

Contents?: true

Size: 657 Bytes

Versions: 1

Compression:

Stored size: 657 Bytes

Contents

module DR
	module Eruby
		begin
			require 'erubis'
			Erb=::Erubis::Eruby
		rescue LoadError
			require 'erb'
			Erb=::ERB
		end
		def erb_include(template, opt={})
			opt={bind: binding}.merge(opt)
			file=File.expand_path(template)
			Dir.chdir(File.dirname(file)) do |cwd|
				erb = Erb.new(File.read(file))
				#if context is not empty, then we probably want to evaluate
				if opt[:evaluate] or opt[:context]
					r=erb.evaluate(opt[:context])
				else
					r=erb.result(opt[:bind])
				end
				#if using erubis, it is better to invoke the template in <%= =%> than
				#to use chop=true
				r=r.chomp if opt[:chomp]
				return r
			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
drain-0.1.0 lib/drain/base/eruby.rb