Sha256: bdc927a751c6badd19b9e6d012937bb3b31ae102bcec03a028b06f65fbd964df
Contents?: true
Size: 1014 Bytes
Versions: 1
Compression:
Stored size: 1014 Bytes
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) Erubis::FastEruby.new(template(*tpl), filename: template_path(*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 template_content(file_path) if CityWatch.debug? TemplateCache[tpl.join] ||= template_content(file_path) end def view_path ViewPath end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
city-watch-0.6.4 | lib/city_watch/util/renderer.rb |