For a small developer documentation app, I'd like to set up a Sinatra app to just serve HAML files. After routes for CSS files and images, I want a route that tries to load a HAML file for any path you request.
For example:
/index
loads views/index.haml
, if it exists/this/page/might/exist
loads views/this/page/might/exist.haml
, if it existsHow would I specify this route?
Looks like this will do it:
get '/*' do
viewname = params[:splat].first # eg "some/path/here"
if File.exist?("views/#{viewname}.haml")
haml :"#{viewname}"
else
"Nopers, I can't find it."
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With