Class: Chuusha::Renderer
- Inherits:
-
Object
- Object
- Chuusha::Renderer
- Defined in:
- lib/chuusha.rb
Instance Method Summary collapse
- #evaluated ⇒ Object
-
#initialize(config, path) ⇒ Renderer
constructor
A new instance of Renderer.
- #render ⇒ Object
- #respond ⇒ Object
- #template_exists? ⇒ Boolean
- #write_cached_copy ⇒ Object
Constructor Details
#initialize(config, path) ⇒ Renderer
Returns a new instance of Renderer.
79 80 81 82 83 84 |
# File 'lib/chuusha.rb', line 79 def initialize(config, path) @config = config @outfile = path @path = @outfile + ".erb" @evaluated = nil end |
Instance Method Details
#evaluated ⇒ Object
90 91 92 93 94 |
# File 'lib/chuusha.rb', line 90 def evaluated return @evaluated if @evaluated eruby = Erubis::Eruby.new(::File.read(@path)) @evaluated = eruby.result(@config.variables) end |
#render ⇒ Object
100 101 102 103 |
# File 'lib/chuusha.rb', line 100 def render write_cached_copy if @config.cache? evaluated end |
#respond ⇒ Object
105 106 107 |
# File 'lib/chuusha.rb', line 105 def respond [200, {"Content-Type" => ::Rack::Mime.mime_type(File.extname(@outfile))}, render] end |
#template_exists? ⇒ Boolean
86 87 88 |
# File 'lib/chuusha.rb', line 86 def template_exists? ::File.exist?(@path) end |
#write_cached_copy ⇒ Object
96 97 98 |
# File 'lib/chuusha.rb', line 96 def write_cached_copy ::File.open(@outfile, "w") { |f| f.write evaluated } end |