Class/Module Index [+]

Quicksearch

Rack::RespondTo::Helpers

Public Class Methods

included(klass) click to toggle source

This code was inherited from respond_to plugin github.com/cehoffman/sinatra-respond_to

This method is used to overide the default content_type returned from rack-accept middleware.

# File lib/sinatra/rack_accept.rb, line 53
def self.included(klass)
  klass.class_eval do
    alias :content_type_without_save :content_type
    def content_type(*args)
      content_type_without_save *args
      request.env['rack-accept.formats'] = { args.first.to_sym => 1 }
      response['Content-Type']
    end
  end
end

Public Instance Methods

accepting_formats() click to toggle source
# File lib/sinatra/rack_accept.rb, line 64
def accepting_formats
  request.env['rack-accept.formats']
end
content_type(*args) click to toggle source
# File lib/sinatra/rack_accept.rb, line 56
def content_type(*args)
  content_type_without_save *args
  request.env['rack-accept.formats'] = { args.first.to_sym => 1 }
  response['Content-Type']
end
respond_to(&block) click to toggle source
# File lib/sinatra/rack_accept.rb, line 74
def respond_to(&block)
  wants = {}
  def wants.method_missing(type, *args, &handler)
    self[type] = handler
  end
  yield wants
  @media_type = accepting_formats.to_a.sort { |a,b| a[1]<=>b[1] }.reverse.select do |format, priority|
    wants.keys.include?(format) == true
  end.first
  if @media_type and @media_type[0]
    @media_type = @media_type[0]
    headers 'Content-Type' => Rack::MediaType::ACCEPTED_MEDIA_TYPES[@media_type][:return]
    wants[@media_type.to_sym].call if wants[@media_type.to_sym]
  else
    headers 'Content-Type' => nil
    status 406
  end
end
static_file?(path) click to toggle source
# File lib/sinatra/rack_accept.rb, line 68
def static_file?(path)
  public_dir = File.expand_path(settings.public)
  path = File.expand_path(File.join(public_dir, unescape(path)))
  path[0, public_dir.length] == public_dir && File.file?(path)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.