2010-07-21 58 views
2

我正在尋找可以讓我拿這樣的事情:尋找一個預處理器,填補了靜態文件

index.html.template:

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

body.html.template:

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

的text.txt:

4 

並把它變成這樣:

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

雖然例子是HTML,我可能會最終使用這樣的事情在很多奇怪的地方。我認爲那裏有一些預處理器;是否有一個非常基本的適合這項任務?

回答

2

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

+0

@Georg點拍攝,描述加入 – Anycorn 2010-07-21 15:18:54

+0

可以工作,但它似乎只生成的.py文件默認情況下。你有一個生成HTML的例子嗎?我目前正在調查文檔... – Chris 2010-07-21 15:25:38

+0

@Chris實際上默認是Html。我也用它來生成C++代碼。 他們是2種模式,編譯和填充。您稍後想要查看4.3節的文檔 – Anycorn 2010-07-21 15:31:30