使用 Ant 生成代码

发布于 2025-01-01 03:19:16 字数 1053 浏览 2 评论 0原文

我想从内联代码片段和其他文件内容的混合内容生成一个文件。比如:

<target name="generate-js-function">
    <concat destfile="mycode.js">
        <header trimleading="yes">
            // begin auto generated
            var create = function() {
                function createHtmlSnippet1() {
        </header>

        <fileset file="snippet1.js"/>

        <header>
                }
        </header>

        <header trimleading="yes">
            // begin auto generated
            var create = function() {
                function createHtmlSnippet2() {
        </header>

        <fileset file="snippet2.js"/>

        <header>
                }
        </header>

                return '' + createHtmlSnippet1() + createHtmlSnippet2();

            }
            // end auto generated
        </header>
    </concat>
</target>

据我所知,只能有一个 header / footer,那么正确的方法是什么?

更新:如果问题中有任何不清楚的地方 - 请询问 - 我会很乐意澄清。

I would like to generate a file from an intermixed content of inline code snippets and contents of other files. Something like:

<target name="generate-js-function">
    <concat destfile="mycode.js">
        <header trimleading="yes">
            // begin auto generated
            var create = function() {
                function createHtmlSnippet1() {
        </header>

        <fileset file="snippet1.js"/>

        <header>
                }
        </header>

        <header trimleading="yes">
            // begin auto generated
            var create = function() {
                function createHtmlSnippet2() {
        </header>

        <fileset file="snippet2.js"/>

        <header>
                }
        </header>

                return '' + createHtmlSnippet1() + createHtmlSnippet2();

            }
            // end auto generated
        </header>
    </concat>
</target>

AFAIK, there can be only one header / footer, so what's the proper way to do it?

Update: if anything in the question isn't clear - please ask - I'll clarify happily.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦明 2025-01-08 03:19:16

对于内联片段,您可以使用 string 资源:

<concat destfile="mycode.js">
  <string>
    // begin auto generated
    var create = function() {
            function createHtmlSnippet1() {
  </string>

  <fileset file="snippet1.js"/>

  <string>
    }
  </string>

  ...

</concat>

唯一的缺点是它不支持 trimleading 属性,但它允许您将代码内联到构建文件中。

For the inline snippets you can use the string resource:

<concat destfile="mycode.js">
  <string>
    // begin auto generated
    var create = function() {
            function createHtmlSnippet1() {
  </string>

  <fileset file="snippet1.js"/>

  <string>
    }
  </string>

  ...

</concat>

The only downside is that it doesn't support the trimleading attribute, but it will allow you to have the code inline in your build file.

深陷 2025-01-08 03:19:16

将每个内联 JS 部分写入其自己的文件中,然后连接所有文件。

您可以使用 echo 任务从 ant 构建文件动态写入临时文件,然后连接片段文件和临时文件。

Write each inline JS portion into its own file, and concat all the files.

You can use the echo task to write to temp files dynamically from the ant build file, and then concat the snippet files and the temp files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文