hassox (owner)

Revisions

gist: 229790 Download_button fork
public
Public Clone URL: git://gist.github.com/229790.git
Embed All Files: show embed
my_stack_content_type_neg_example.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
##### 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