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

Version Path
city-watch-0.7.9 lib/city_watch/util/renderer.rb
city-watch-0.7.8 lib/city_watch/util/renderer.rb
city-watch-0.7.7 lib/city_watch/util/renderer.rb
city-watch-0.7.6 lib/city_watch/util/renderer.rb
city-watch-0.7.5 lib/city_watch/util/renderer.rb
city-watch-0.7.4 lib/city_watch/util/renderer.rb
city-watch-0.7.3 lib/city_watch/util/renderer.rb
city-watch-0.7.2 lib/city_watch/util/renderer.rb
city-watch-0.7.1 lib/city_watch/util/renderer.rb
city-watch-0.7.0 lib/city_watch/util/renderer.rb
city-watch-0.6.9 lib/city_watch/util/renderer.rb
city-watch-0.6.8 lib/city_watch/util/renderer.rb
city-watch-0.6.7 lib/city_watch/util/renderer.rb
city-watch-0.6.6 lib/city_watch/util/renderer.rb
city-watch-0.6.5 lib/city_watch/util/renderer.rb