Sha256: 42b329fb43ff16981d65e863adb0a18d696c2e5425aa5fb5e0776ea6ffa87204

Contents?: true

Size: 844 Bytes

Versions: 3

Compression:

Stored size: 844 Bytes

Contents

require 'tilt'
class Rack::App::FrontEnd::Template

  require 'rack/app/front_end/template/default_layout'

  def self.cache
    @cache ||= Tilt::Cache.new
  end

  def render(*args, &block)
    return render_result(*args, &block)
  end

  protected

  def initialize(file_path, options={})
    @file_path = file_path
    @options = options
  end

  def render_result(*args, &block)
    return Rack::App::File::Streamer.new(@file_path) unless it_is_a_template?

    layout.render { template.render(*args, &block) }
  end

  def it_is_a_template?
    not Tilt.templates_for(@file_path).empty?
  end

  def template
    get_template(@file_path)
  end

  def layout
    @options[:layout] ? get_template(@options[:layout]) : DefaultLayout
  end

  def get_template(file_path)
    self.class.cache.fetch(file_path) { Tilt.new(file_path) }
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack-app-front_end-0.10.0 lib/rack/app/front_end/template.rb
rack-app-front_end-0.8.0 lib/rack/app/front_end/template.rb
rack-app-front_end-0.7.0 lib/rack/app/front_end/template.rb