Sha256: 6201f1417018004aeae49d46c61be24ddf27448e3a41130c6fda5f5bbfff739c

Contents?: true

Size: 665 Bytes

Versions: 3

Compression:

Stored size: 665 Bytes

Contents

require 'erb'
require 'ostruct'

class Sfp::TemplateEngine < OpenStruct
	def render(template)
		ERB.new(template).result(binding)
	end

	def render_to_file(template, file)
		result = render(template)
		File.open(file, 'w+') { |f| f.write(result) }
	end

	def render_file(file)
		render_to_file(File.read(file), file)
	end

	def self.render(map, template)
		renderer = TemplateEngine.new(map)
		renderer.render(template)
	end

	def self.render_to_file(map, template, file)
		renderer = TemplateEngine.new(map)
		renderer.render_to_file(template, file)
	end

	def self.render_file(map, file)
		renderer = TemplateEngine.new(map)
		renderer.render_file(file)
	end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sfpagent-0.3.2 lib/sfpagent/templateEngine.rb
sfpagent-0.3.1 lib/sfpagent/templateEngine.rb
sfpagent-0.3.0 lib/sfpagent/templateEngine.rb