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