如何使用Sinatra或Padrino从HAML自动生成静态HTML? [英] How do I automatically generate static HTML from HAML with Sinatra or Padrino?

查看:98
本文介绍了如何使用Sinatra或Padrino从HAML自动生成静态HTML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用nginx提供静态HTML页面.然后,我将使用jQuery通过来自Padrino服务器的AJAX调用来更新DIV,SPAN等.

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.

我喜欢在HAML中创建网页,因为它更容易,但是在生产中,我不想提供HAML模板.只是原始的HTML,以nginx的速度.

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?

理想的情况是将自动将HAML,局部文件等呈现到nginx可以服务的公用文件夹中的服务.

What would be ideal would be a service that automatically renders HAML, partials, etc into the public folder that nginx could serve.

推荐答案

简单

将padrino-cache添加到您的应用

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'))

您可以在此处了解更多信息: http://www.padrinorb.com/guides/padrino-缓存

You can read more here: http://www.padrinorb.com/guides/padrino-cache

这篇关于如何使用Sinatra或Padrino从HAML自动生成静态HTML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆