Sha256: eff9c3148e86c39f822cf26f4e744617b694e35673e180e9023c2923133a72d3

Contents?: true

Size: 748 Bytes

Versions: 1

Compression:

Stored size: 748 Bytes

Contents

module Brochure
  class Template
    attr_reader :app, :path

    def initialize(app, path)
      @app  = app
      @path = path
    end

    def template
      @template ||= Tilt.new(path)
    end

    def engine_extension
      @engine_extension ||= File.extname(path)
    end

    def format_extension
      @format_extension ||= begin
        ext = File.extname(File.basename(path, engine_extension))
        ext.empty? ? ".html" : ext
      end
    end

    def content_type
      @content_type ||= begin
        type = Rack::Mime.mime_type(format_extension)
        type[/^text/] ? "#{type}; charset=utf-8" : type
      end
    end

    def render(env, locals = {})
      template.render(app.context_for(self, env), locals)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
brochure-0.4.0 lib/brochure/template.rb