English 中文(简体)
静态模板中包含html代码的序号
原标题:Use ant to wrap html code in static template

我有数份超文本文件,存放在不同地点(共同根基),例如:

index.html
moduleA/list.html
moduleA/add.html
moduleB/list.html
moduleB/add.html
...

Additionally I have one file called -template.html, that contains HTML code and a placeholder #CONTENT#. What I need:

  1. Copy all HTML files to public/ directory
  2. Each HTML file in public/ directory should also have code from -template.html wrapped around the original content.

I use ANT to copy the files, but I cannot figure out how to wrap the template-code around the code... My ANT script looks like this:

<project default="build">
    <target name="build">
        <copy todir="${dir.intermediate}/temp">
            <fileset dir="${dir.source}" includes="**/*.html"/>
        </copy>
    </target>
</project>

Example:

指数.html

<div>This is the index-page</div>

-template.html

<html>
    <head><title>Page-Title</title></head>
    <body>
        #CONTENT#
    </body>
</html>

如果产生产出档案:

<html>
    <head><title>Page-Title</title></head>
    <body>
        <div>This is the index-page</div>
    </body>
</html>
最佳回答

如果你想要坚持既定任务,一个可能的工作是把你的模板文件分为两个档案,即“前”部分,如:

<html>
  <head><title>Page-Title</title></head>
  <body>

and a "post" section like this:

  </body>
</html>

然后,请在concatfilter <>> >上在filterchain内插入。 任务:

<copy todir="${dir.intermediate}/temp">
  <fileset dir="${dir.source}" includes="**/*.html"/>
  <filterchain>
    <concatfilter prepend="src/_template_pre.html" append="src/_template_post.html" />
  </filterchain>
</copy>

我看看不出在不使用ant或说明等内容的情况下用单一模板文档做任何事情。

问题回答

这完全有可能完成单纯的任务:

第一个将“替换”装入一个财产的使用文件:

<loadfile property="replacement" srcFile="index.html"/>

Then after copying your template somehwere, where the final file will be do this :

<replaceregexp file="${my.final.file}"
               match="#CONTENT#"
               replace="${replacement}"
/>

您的档案现在应该是:





相关问题
Enabling Ant Tools in a new Eclipse Galileo installation

I have recently installed Eclipse Galileo with the PHP Developers Tools. I plan to install the Flash Builder 4 Plug-in to do ActionScript development as well. I want to use Eclipse to both create an ...

Continuous Integration with Teamcity and Clearcase

Has anybody successfully integrated Clearcase with Teamcity (which advertises Clearcase support) to realize a productive continuous integration build environment on a decent size project?

热门标签