How do I automatically generate static HTML from HAML with Sinatra or Padrino?

梦想的初衷 提交于 2019-12-25 08:15:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!