Sha256: 1b54723815966627e0df290e7c9f4eb64b880131a4f5f364ee5ba664512f69ee

Contents?: true

Size: 752 Bytes

Versions: 1

Compression:

Stored size: 752 Bytes

Contents

require 'tilt'

module AsciiBinderGabrielRH
  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

1 entries across 1 versions & 1 rubygems

Version Path
ascii_binder_gabriel_rh-0.0.1 lib/ascii_binder_gabriel_rh/template_renderer.rb