问题
I want to serve static HTML pages using nginx
. Then, I will use jQuery
to update DIVs, SPANs, etc via AJAX calls from a Padrino server.
I like creating my web pages in HAML because it's easier but in production, I don't want to serve HAML templates. Just raw, HTML at the speed of nginx.
Is there an easy way to do this?
What would be ideal would be a service that automatically renders HAML, partials, etc into the public folder that nginx could serve.
回答1:
Simple,
add padrino-cache to your app
class SimpleApp < Padrino::Application
register Padrino::Cache
enable :caching
get '/foo', :cache => true do
expires_in 30 # expire cached version at least every 30 seconds
'Hello world'
end
end
Then save wherever you want to serve it:
set :cache, Padrino::Cache::Store::File.new(Padrino.root('public'))
You can read more here: http://www.padrinorb.com/guides/padrino-cache
回答2:
First thing that pops to my mind would be Jekyll. Anyway I see it only as a matter or optimization, so if you already have a Sinatra, you could start by rendering HAML on every request, and than add caching.
来源:https://stackoverflow.com/questions/10236456/how-do-i-automatically-generate-static-html-from-haml-with-sinatra-or-padrino