3

これは些細なことだと確信しています-しかし、壁に頭をぶつけていました。口ひげのテンプレート(基本的にhtmlファイル)でいっぱいのディレクトリを取得して、それらを1つのファイルに結合しようとしています-それぞれをタグでラップします

例:

File1 = <a>This is a Link</a>
File2 = <b>This is in bold</b>

出力を次のようにしたい:

<script type="text/mustache" id="File1">
 <a>This is a Link</a>
</script>
<script type="text/mustache" id="File2">
 <b>This is in bold</b>
</script>

連結タスクを使用しています

<concat destfile="mustache.js" fixlastline="yes">
 <fileset dir="." includes="**/*.mustache"/>
</concat>

しかし、スクリプトブロックを表示する方法がわかりません

4

1 に答える 1

1

最初は、ヘッダーとフッターで 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 タスク内の一番左の表記は、結果のファイルに不要な空白が含まれないようにします。上記の例のように書くだけで、ファイルは必要な
出力
のようになります<![CDATA[...]]>

于 2011-08-31T20:47:44.683 に答える