Skip to content

Instantly share code, notes, and snippets.

@aliang

aliang/gist:263863

Forked from retr0h/gist:98308
Created Dec 26, 2009
Embed
What would you like to do?
content type handling for sinatra
CONTENT_TYPES = {:html => 'text/html', :css => 'text/css', :js => 'application/javascript'}
before do
# instead of using case here, metaprogram it
request_uri = case request.env['REQUEST_URI']
when /\.css$/ : :css
when /\.js$/ : :js
else :html
end
content_type CONTENT_TYPES[request_uri], :charset => 'utf-8'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment