Sha256: 1c93a4103de0a4a2e32cfcb11cb822a4faa17206b33cbd8739af7b85e6197e7d
Contents?: true
Size: 743 Bytes
Versions: 28
Compression:
Stored size: 743 Bytes
Contents
require 'tilt' module AsciiBinder class TemplateRenderer attr_reader :source_dir, :template_cache def initialize(source_dir,template_directory) @source_dir = source_dir @template_cache = {} Dir.glob(File.join(template_directory, "**/*")).each do |file| @template_cache[file] = Tilt.new(file, :trim => "-") end end def render(template, args = {}) # Inside erb files, template path is local to repo if not template.start_with?(source_dir) template = File.join(source_dir, template) end renderer_for(template).render(self, args).chomp end private def renderer_for(template) template_cache.fetch(File.expand_path(template)) end end end
Version data entries
28 entries across 28 versions & 1 rubygems