Module: Wunderbar::Template::Text

Defined in:
lib/wunderbar/sinatra.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extObject



143
# File 'lib/wunderbar/sinatra.rb', line 143

def self.ext; ['text.rb', :_text]; end

.mimeObject



144
# File 'lib/wunderbar/sinatra.rb', line 144

def self.mime; 'text/plain'; end

Instance Method Details

#evaluate(scope, locals, &block) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/wunderbar/sinatra.rb', line 146

def evaluate(scope, locals, &block)
  builder = TextBuilder.new(scope)
  begin
    result = _evaluate(builder, scope, locals, &block)

    # if no output was produced, use the result
    builder._ result.to_s if builder.target!.empty? and result

    scope.response.status = 404 if builder.target!.empty?
  rescue Exception => exception
    scope.headers['Content-Type'] = self.class.default_mime_type
    scope.response.status = Wunderbar::ServerError.status
    builder._exception exception
  end
  builder.target!
end