Included Modules

Sinatra::RespondWith::Helpers

Public Instance Methods

respond_to(&block) click to toggle source
# File lib/sinatra/respond_with.rb, line 160
def respond_to(&block)
  Format.new(self).finish(&block)
end
respond_with(template, object = nil, &block) click to toggle source
# File lib/sinatra/respond_with.rb, line 130
def respond_with(template, object = nil, &block)
  object, template = template, nil unless Symbol === template
  format = Format.new(self)
  format.on "*/*" do |type|
    exts = settings.ext_map[type]
    exts << :xml if type.end_with? '+xml'
    if template
      args = template_cache.fetch(type, template) { template_for(template, exts) }
      if args.any?
        locals = { :object => object }
        locals.merge! object.to_hash if object.respond_to? :to_hash

        renderer = args.first
        options = args[1..-1] + [{:locals => locals}]

        halt send(renderer, *options)
      end
    end
    if object
      exts.each do |ext|
        halt json(object) if ext == :json
        next unless object.respond_to? method = "to_#{ext}"
        halt(*object.send(method))
      end
    end
    false
  end
  format.finish(&block)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.