Couldn’t get that last thing to work so keeping it simple (stupid)
This could undoubtedly be more elegant, but it’s late and I want it to work now. May take another stab at it later…
TODO: limit the content types and only allow rendering if they are ok.
Setting up a before filter:
1 2 3 4 5 6 7 | before do # remove and grab the file extension request.path_info.sub! %r{\.([^\./]+)$}, '' @format=$1 || 'html' @charset=mime_type($1) || 'text/html' content_type @charset, :charset => 'utf-8' end |
and using a case statement:
1 2 3 4 5 6 7 8 9 10 11 | get "/home" do case @format when 'html' @stylesheet='home.css' haml :home, :layout=>:layout_simple when 'js' "{'js':true}" else pass end end |