Sha256: 9f3984e70316698e62f94fd2d6a27dda86864a538797fea10e165ee84159f44b

Contents?: true

Size: 533 Bytes

Versions: 3

Compression:

Stored size: 533 Bytes

Contents

require 'tilt'

module AsciiBinder
  class TemplateRenderer
    def self.template_cache
      @template_cache ||= {}
    end

    def self.initialize_cache(directory)
      Dir.glob(File.join(directory, "**/*")).each do |file|
        template_cache[file] = Tilt.new(file, :trim => "-")
      end
    end

    def render(template, args = {})
      renderer_for(template).render(self, args).chomp
    end

    private

    def renderer_for(template)
      self.class.template_cache.fetch(File.expand_path(template))
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ascii_binder-0.0.7 lib/ascii_binder/template_renderer.rb
ascii_binder-0.0.6 lib/ascii_binder/template_renderer.rb
ascii_binder-0.0.5 lib/ascii_binder/template_renderer.rb