Sha256: e502ce9a72e087b0261334285ecaa51087201b87876b28b7e9f61ade4e891a92
Contents?: true
Size: 1.02 KB
Versions: 15
Compression:
Stored size: 1.02 KB
Contents
require 'erubis' TemplateCache = {} ViewPath = File.expand_path(File.dirname(__FILE__) + "/../../../views") Layout = Proc.new { file_path = "#{ViewPath}/layouts/default.html.erb" Erubis::FastEruby.new(File.read(file_path), bufvar: '@output_buffer', filename: file_path) }.call module Renderer def render(*tpl) layout do render_bare(*tpl) end end def render_bare(*tpl) template(*tpl).result(binding) end private def layout(&block) Layout.result(binding) end def template_content(file_path) return "" unless file_path File.read(file_path) end def template_path(*tpl) tpl.map {|t| "#{view_path}/#{t}.html.erb" }.detect{|p| File.exists?(p) } end def template(*tpl) return TemplateCache[tpl.join] if TemplateCache[tpl.join] file_path = template_path(*tpl) return Erubis::FastEruby.new(template_content(file_path), filename: file_path) if CityWatch.debug? TemplateCache[tpl.join] ||= Erubis::FastEruby.new(template_content(file_path), filename: file_path) end def view_path ViewPath end end
Version data entries
15 entries across 15 versions & 1 rubygems