我使用grunt將灰塵模板中的標記複製到JSP。我有很多JSP頁面,我希望用本地化類替換跨頁,並帶有彈簧標籤grunt如何取代HTML元素?
<div class="push-right">
<a href="/credentials/login">
<span class="localize" name="top_bar.sign_in">Sign In</span>
</a> |
<a href="/credentials/register">
<span class="localize" name="top_bar.register">Register</span>
</a>
</div>
因此,此塊應該變成這樣。
<div class="push-right">
<a href="/credentials/login">
<spring:message code="top_bar.sign_in" />
</a> |
<a href="/credentials/register">
<spring:message code="top_bar.register" />
</a>
</div>
UPDATE @Sam規定,我現在下一個良好的正則表達式的例子。我建設,我推到一個數組
var reLocalize = new RegExp('<span(?=[^>]*?class="localize").*?name="([^"]*).*?<\/span>', 'g');
localizeReplaceObject.match = reLocalize;
localizeReplaceObject.replacement = '<spring:message code=$1 />';
localizeReplaceArray.push(localizeReplaceObject);
然後我跑咕嚕的對象替換
replace: {
localize: {
options: {
patterns: localizeReplaceArray
}
,files: [
{expand: true, flatten: true, src: ['../WEB-INF/views/index.jsp'], dest: '../WEB-INF/views/'}
]
}
我再次運行咕嚕grunt replace:localize
但index.jsp的定位標籤不更新。
Running "replace:localize" (replace) task
Verifying property replace.localize exists in config...OK
Files: ../WEB-INF/views/index.jsp -> ../WEB-INF/views/index.jsp
Options: encoding="utf8", mode=false, processContentExclude=[], patterns=[{"match":{},"replacement":"<spring:message code=$1 />"}], excludeBuiltins=false, force
filePair src ../WEB-INF/views/index.jsp
Reading ../WEB-INF/views/index.jsp...OK
Processing source...Replace ../WEB-INF/views/index.jsp → ../WEB-INF/views/index.jsp
OK
Writing ../WEB-INF/views/index.jsp...OK
Done, without errors.
我不知道如何做到這一點,但你可以做到這一點 - 最快的解決方案將從命令提示符,選擇文件夾和文件,並運行重命名,你會得到足夠的教程在谷歌 – 2014-10-02 05:22:55
jQuery的作品在DOM/XML節點,而不是HTML源。除非Grunt環境中有些我還不知道的東西,否則你所要求的東西似乎是不可能的。 – 2014-10-02 05:27:15
我指的是jquery'$ .each'作爲比喻。有沒有辦法在grunt中通過屬性名稱中的管道替換內容來實現此循環功能? – 2014-10-02 05:31:58