起初我想以某种方式将 concat 与页眉和页脚一起使用,但没有找到可行的解决方案。
如果您不回避使用一些 Ant 插件,这里有一个基于Flaka的解决方案=
<project name="demo" xmlns:fl="antlib:it.haefelinger.flaka">
<!-- make standard ant tasks understand EL expressions -->
<fl:install-property-handler />
<!-- we use path instead of pure fileset because we need
absolute filenames for loadfile later in for loop -->
<path id="foo">
<fileset dir="/some/path" includes="**/*.mustache"/>
</path>
<!-- iterate over the path/fileset -->
<fl:for var="file" in="split('${toString:foo}', ':')">
<!-- unset property for next loop -->
<fl:unset>content</fl:unset>
<!-- load file contents to property -->
<loadfile property="content" srcFile="#{file}"/>
<echo file="/some/path/foobar/mustache.js" append="true">
<!-- the id attribute gets filled with the basename of the current fileitem -->
<![CDATA[<script type="text/mustache" id="#{replace(file, '$1' , '.+?(\w+)\..+' )}">
#{trim('${content}')}
</script>]]></echo>
</fl:for>
</project>
注意:
1.我在 echo 任务中最左边的符号以避免结果文件中出现不必要的空白!
只需按照我上面的示例编写,您的文件将看起来像您想要的输出
2.<![CDATA[...]]>
是必需的,否则您会收到一些错误,例如“echo 不支持嵌套的“脚本”元素。”