class Rack::App::FrontEnd::Template
Constants
- DEFAULT_TEMPLATE_OPTIONS
Public Class Methods
cache()
click to toggle source
# File lib/rack/app/front_end/template.rb, line 8 def self.cache @cache ||= Tilt::Cache.new end
new(template_path, options={})
click to toggle source
# File lib/rack/app/front_end/template.rb, line 25 def initialize(template_path, options={}) @file_path = template_path @layout_path = options.delete(:layout_path) @template_options = DEFAULT_TEMPLATE_OPTIONS.merge(options) end
template?(file_path)
click to toggle source
# File lib/rack/app/front_end/template.rb, line 12 def self.template?(file_path) not Tilt.templates_for(file_path).empty? end
Public Instance Methods
render(scope, variables={}, &block)
click to toggle source
# File lib/rack/app/front_end/template.rb, line 16 def render(scope, variables={}, &block) layout.render(scope, variables) { template.render(scope, variables, &block) } end
Protected Instance Methods
get_template(file_path)
click to toggle source
# File lib/rack/app/front_end/template.rb, line 51 def get_template(file_path) self.class.cache.fetch(file_path) { Tilt.new(file_path, @template_options) } end
layout()
click to toggle source
# File lib/rack/app/front_end/template.rb, line 39 def layout return DefaultLayout if use_default_layout? get_template(@layout_path) end
template()
click to toggle source
# File lib/rack/app/front_end/template.rb, line 31 def template if self.class.template?(@file_path) get_template(@file_path) else DefaultTemplate.new(@file_path) end end
use_default_layout?()
click to toggle source
# File lib/rack/app/front_end/template.rb, line 45 def use_default_layout? @layout_path.nil? or not File.exist?(@layout_path) or (@file_path =~ /^#{Regexp.escape(Rack::App::Utils.namespace_folder(@layout_path))}/) end