【问题标题】:Mustache & Sinatra - is it possible to omit the view.rb file?Mustache & Sinatra - 是否可以省略 view.rb 文件?
【发布时间】:2011-11-08 14:50:17
【问题描述】:

我将 Mustache 模板库与 Sinatra 一起使用,标准方法似乎是在 /templates 下创建 index.mustache 以及在 /views 中子类 Mustache 的关联 index.rb。

对于像关于页面这样的东西,根本没有发生任何特殊逻辑,怎么可能只使用 .mustache 模板并仍然在 Sinatra 中执行以下操作:

get "/" do
  mustache :about
end

当我根本不提供 index.rb 文件时,Mustache 会抛出一个关于无法找到它的错误。

【问题讨论】:

  • 不确定 mustache 但使用 haml 你可以使用 Haml::Engine.new("%p foo").render 进行内联渲染,mustache 可能有类似的方法
  • Doh,我误读了您的问题,以为您要在没有任何模板的情况下进行渲染。

标签: ruby sinatra mustache


【解决方案1】:

我认为解决方案非常简单。如果您没有视图模型(例如 index.rb),您只需使用另一个模板系统,例如 erb

erb :about

或者如果文件是静态的,就把它放在这里

./public/about.html

没有视图模型的 .mustache 模板是没有意义的。

【讨论】:

    【解决方案2】:

    这个视图要求很烦人。 Jason Campbell 通过https://github.com/jxson/sinatra-mustache 来救援

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 2021-02-18
      • 1970-01-01
      • 2022-01-21
      • 2019-11-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多