Class: Chuusha::Renderer

Inherits:
Object
  • Object
show all
Defined in:
lib/chuusha.rb

Instance Method Summary collapse

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

#evaluatedObject



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

#renderObject



100
101
102
103
# File 'lib/chuusha.rb', line 100

def render
  write_cached_copy if @config.cache?
  evaluated
end

#respondObject



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

Returns:

  • (Boolean)


86
87
88
# File 'lib/chuusha.rb', line 86

def template_exists?
  ::File.exist?(@path)
end

#write_cached_copyObject



96
97
98
# File 'lib/chuusha.rb', line 96

def write_cached_copy
  ::File.open(@outfile, "w") { |f| f.write evaluated }
end