Module: Wunderbar::Template::Json

Defined in:
lib/wunderbar/sinatra.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extObject



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

def self.ext; ['json.rb', :_json]; end

.mimeObject



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

def self.mime; 'application/json;charset=utf-8'; end

Instance Method Details

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



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/wunderbar/sinatra.rb', line 124

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

    # if no output was produced, use the result
    builder._! result if builder.target? == {} and result

  rescue Exception => exception
    scope.content_type self.class.default_mime_type, :charset => 'utf-8'
    scope.response.status = Wunderbar::ServerError.status
    builder._exception exception
  end
  scope.cache_control :no_cache
  builder.target!
end