【问题标题】:Looking for a preprocessor to fill in static files寻找预处理器来填充静态文件
【发布时间】:2011-03-19 01:16:11
【问题描述】:

我正在寻找的东西可以让我接受这样的事情:

index.html.template:

<html>
<body>
<# include ("body.html.template") #>
</body>
</html>

body.html.template:

Hello World! <# include("text.txt") #>

文本.txt:

4

然后把它变成这样:

<html>
<body>
Hello World! 4
</body>
</html>

虽然示例是 HTML,但我可能最终会在很多奇怪的地方使用类似的东西。我认为那里有许多预处理器。有适合这项任务的非常基本的吗?

【问题讨论】:

    标签: templates code-generation preprocessor html-generation


    【解决方案1】:

    http://www.cheetahtemplate.org/

    它基本上是嵌入在模板中的 python 语句,因此您可以访问所有 python 功能。小例子:

    #for $i in $range(10)
    #set $step = $i + 1
    $step.  Counting from 1 to 10.
    #end for
    

    会产生

    0.  Counting from 1 to 10.
    1.  Counting from 1 to 10.
    ...
    

    此链接文件包含指令: http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000860000000000000000

    【讨论】:

    • 这可以工作,但默认情况下它似乎只生成 .py 文件。您有生成 HTML 的示例吗?我目前正在调查文档...
    • @Chris 实际上默认是 Html。我也用它来生成 C++ 代码。它们是 2 种模式,编译和填充。稍后,请查看文档中的第 4.3 节
    • @aaa 听起来不错。所以从这里看起来我会写 cheetah compile --iext html.tmpl --oext html 来生成 html?
    • @Chris cheetah fill a.tmpl 应该足以创建一个.html
    • @aaa 哦,我的意思是作为一个通用系统,所以我可以做 cheetah compile --iext js.tmpl --oext js,例如。感谢您的帮助!
    猜你喜欢
    • 2018-11-11
    • 2021-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多