Skip to content

Instantly share code, notes, and snippets.

@hassox
Created November 9, 2009 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hassox/229790 to your computer and use it in GitHub Desktop.
Save hassox/229790 to your computer and use it in GitHub Desktop.
##### ContentType negotiation
# Add a mime type
Pancake::MimeTypes::Type.new("foo", "text/foo")
Pancake::MimeTypes::Type.new("special", "text/plain")
# Group mime types together to simplify responding
Pancake::MimeTypes.group_as(:html, "xhtml", "foo")
Pancake::MimeTypes.group_as(:special, "special", "log")
# Low level usage
Pancake::MimeType.negotiate_accept_type(accept_type, :html, :special)
# Use in a short stack
class MyShortStack < Pancake::Stacks::Short
provides :html, :special
get "/foo(.:format)" do
case content_type
when :html
# respond with html
when :special
# respond with special
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment