Module: Wunderbar::Template::Text

Defined in:
lib/wunderbar/sinatra.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extObject



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

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

.mimeObject



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

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

Instance Method Details

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



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/wunderbar/sinatra.rb', line 154

def evaluate(scope, locals, &block)
  builder = TextBuilder.new(scope)
  begin
    result = _evaluate_safely(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 = 500
    builder._exception exception
  end
  builder.target!
end