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

Version Path
ascii_binder-1.2 lib/ascii_binder/template_renderer.rb
ascii_binder-1.0.1 lib/ascii_binder/template_renderer.rb
ascii_binder-1.0 lib/ascii_binder/template_renderer.rb
ascii_binder-0.2.3 lib/ascii_binder/template_renderer.rb
ascii_binder-0.2.2 lib/ascii_binder/template_renderer.rb
ascii_binder-0.2.1 lib/ascii_binder/template_renderer.rb
ascii_binder-0.2.0 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.15.3 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.15.2 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.15.1 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.15 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.14 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.13 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.11 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.10.1 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.10 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.9 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.8 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.7 lib/ascii_binder/template_renderer.rb
ascii_binder-0.1.6 lib/ascii_binder/template_renderer.rb