Htmlタグのプロパティ文法ジャケット
2406 ワード
Common Template(
http://www.commontemplate.org)のHtmlタグ属性文法ジャケットはプロジェクトの重要なFeatureです。
例えば:
http://htmlparser.sourceforge.net)しかし、この機能を実現するのは不便であり、必要は簡単であり、特殊な名前空間の属性を「両端の内容」に変換することである。
この機能はCommon Templateだけではなく、他のテンプレートエンジン(Velocity/FreeMaker)と同じように使えますので、html parserにお願いします。そして、私が望むAPIを提供しました。
http://www.commontemplate.org)のHtmlタグ属性文法ジャケットはプロジェクトの重要なFeatureです。
例えば:
<table ct:if="users != null && users.size > 0" border="1">
<tr ct:for="user : users">
<td><span ct:out="for.index + 1">1</span></td>
<td><span ct:out="user.name">james</span></td>
<td><span ct:out="user.coins">2.00</span></td>
</tr>
</table>
フィルタ後:
$if{users != null && users.size > 0}
<table border="1">
$for{user : users}
<tr>
<td>$out{for.index + 1}<span>1</span>$end</td>
<td>$out{user.name}}<span>james</span>$end</td>
<td>$out{user.coins}}<span>2.00</span>$end</td>
</tr>
$end
</table>
$end
現在のバージョンは自己解析で、違法なHtmlフォーマットの許容性が弱く、自動的に閉じられていないラベルなどの簡単な処理を行いました。機能を早く安定させるために、他のHtmlフォールトトレランス解析キットを使って解析します。成熟したのはHtmlPaserです。http://htmlparser.sourceforge.net)しかし、この機能を実現するのは不便であり、必要は簡単であり、特殊な名前空間の属性を「両端の内容」に変換することである。
この機能はCommon Templateだけではなく、他のテンプレートエンジン(Velocity/FreeMaker)と同じように使えますので、html parserにお願いします。そして、私が望むAPIを提供しました。
// Tag
public final class Coat {
private final String before;
private final String after;
public Coat(String before, String after) {
this.before = before;
this.after = after;
}
public String getBefore() {
return before;
}
public String getAfter() {
return after;
}
}
public interface AttributeCoatHandler {
// ,
// Coat before after Tag
Coat handleAttribute(String attrName, String attrValue);
}
//
TagCoatContext.registerAttributeCoatHandler(String namespace, AttributeCoatHandler handler);
彼らが実現することができることを望んで、もし駄目ならば、自分で書くかもしれなくて、先に遅延計画の中に参加します。