如何处理 Template Toolkit 中的模板依赖关系?
我的静态网页是由大量模板构建的,这些模板使用 Template Toolkit 的“导入”和“包含”相互包含,因此 page.html 看起来像这样:
[% INCLUDE top %]
[% IMPORT middle %]
然后 top 可能包含更多文件。
我有很多这样的文件,必须运行它们才能创建各种语言(英语、法语等,而不是计算机语言)的网页。这是一个非常复杂的过程,当更新一个文件时,我希望能够使用 makefile 或类似的文件自动重新制作必要的文件。
是否有像 makedepend
这样的 C 文件工具可以解析模板工具包模板并创建在 makefile 中使用的依赖项列表?
或者有更好的方法来自动化这个过程吗?
My static web pages are built from a huge bunch of templates which are inter-included using Template Toolkit's "import" and "include", so page.html looks like this:
[% INCLUDE top %]
[% IMPORT middle %]
Then top might have even more files included.
I have very many of these files, and they have to be run through to create the web pages in various languages (English, French, etc., not computer languages). This is a very complicated process and when one file is updated I would like to be able to automatically remake only the necessary files, using a makefile or something similar.
Are there any tools like makedepend
for C files which can parse template toolkit templates and create a dependency list for use in a makefile?
Or are there better ways to automate this process?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Template Toolkit
确实附带了自己的命令行脚本,称为ttree
用于构建 TT 网站。这是我在 Mac 上的 TT 网站项目中经常使用的
ttree.cfg
文件:只需运行
ttree -f ttree.cfg
将在中重建网站dest
仅更新源代码(在src
中)或我的库(在lib
中)中更改的内容。有关更细粒度的依赖项,请查看
模板依赖项
。更新 - 这是我通过子类化
Template::Provider
:上面的代码显示了调用的所有依赖项(通过 INCLUDE、INSERT、PROCESS 和 WRAPPER)以及从整个
root 内部调用的位置.tt
树。因此,您可以从此构建一个ttree
依赖文件。/I3az/
Template Toolkit
does come with its own command line script calledttree
for building TT websites ala make.Here is an
ttree.cfg
file I use often use on TT website projects here on my Mac:Just running
ttree -f ttree.cfg
will rebuild the site indest
only updating whats been changed at source (insrc
) or in my libraries (inlib
).For more fine grained dependencies have a look a
Template Dependencies
.Update - And here is my stab at getting dependency list by subclassing
Template::Provider
:The code above displays all dependencies called (via INCLUDE, INSERT, PROCESS and WRAPPER) and where called from within the whole
root.tt
tree. So from this you could build attree
dependency file./I3az/
如果您关心的只是查找
INCLUDE
、PROCESS
、WRAPPER
等指令中提到的文件名,甚至可以想象使用从命令行使用 sed
或perl
来生成依赖项。但是,如果存在更微妙的依赖性(例如,您在 HTML 文档中使用
引用图像,其大小是使用 图像插件,问题可能会变得更不容易处理。
我还没有真正测试过它,但类似下面的东西可能会起作用:
In case all you care about are finding file names mentioned in directives such as
INCLUDE
,PROCESS
,WRAPPER
etc, one imagine even usingsed
orperl
from the command line to generate the dependencies.However, if there are subtler dependencies (e.g., you reference an image using
<img>
in your HTML document whose size is calculated using the Image plugin, the problem can become much less tractable.I haven't really tested it but something like the following might work:
阅读 ttree 文档后,我决定自己创建一些东西。我将其发布在这里,以防它对下一个来的人有用。然而,这不是一个通用的解决方案,而是仅适用于少数有限的情况。它适用于该项目,因为所有文件都位于同一目录中并且没有重复的包含。我已将缺陷记录为每个例程之前的注释。
如果有一个简单的方法可以对我错过的 ttree 执行此操作,请告诉我。
After reading the ttree documentation, I decided to create something myself. I'm posting it here in case it's useful to the next person who comes along. However, this is not a general solution, but one which works only for a few limited cases. It worked for this project since all the files are in the same directory and there are no duplicate includes. I've documented the deficiencies as comments before each of the routines.
If there is a simple way to do what this does with ttree which I missed, please let me know.