在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 物聯(lián)網(wǎng)/ grunt.template
深入任務內(nèi)幕
grunt.option
退出碼
創(chuàng)建插件
grunt.file
grunt
快速入門
項目腳手架
使用命令行工具
Gruntfile 實例
配置任務
創(chuàng)建任務
grunt.log
安裝Grunt
grunt.util
grunt.event
常見問題
grunt.config
grunt.task
grunt.template
grunt.fail

grunt.template

可以使用Grunt提供的模板相關(guān)函數(shù)來手動的處理模板字符串。此外,config.get方法(許多任務都有用到這個方法)可以自動解析指定在Gruntfile中作為配置數(shù)據(jù)的<% %>風格的模板字符串。

grunt.template.process

處理Lo-Dash模板字符串。template參數(shù)會以遞歸的方式進行處理,直到不再有需要處理的模板。

默認情況下數(shù)據(jù)對象就是項目完整的配置對象,但是如果設置了options.data,就會使用這個options.data中指定的數(shù)據(jù),而不會使用項目完整的配置對象。默認的模板分隔符是<% %>,但是如果將options.delimiters設置為自定義的分隔符,模板就會使用自定義的分隔符替換默認分隔符。

grunt.template.process(template [,options])

在模板內(nèi)部,grunt對象是暴露的,因此你可以這樣做<%= grunt.template.tody('yyyy') %>注意,如果數(shù)據(jù)對象也有一個名為grunt的屬性,那么在模板里面就無法使用grunt系列的API。

這里有一個例子,Grunt會以遞歸的方式處理到baz屬性中的模板,知道不再有<% %>風格的模板需要處理。

var obj = {
    foo: 'c',
    bar: 'b<%= foo %>d',
    baz: 'a<%= bar %>e'
};
grunt.template.process('<%= baz %>', {data: obj}) // 'abcde'

grunt.template.setDelimiters

設置Lo-Dash模板分隔符為預定義的分隔符,以防你需要手動的調(diào)用grunt.util._.template方法來進行處理。默認情況下config中會使用<% %>風格的分隔符。

你或許無需使用這個方法,因為你所使用的grunt.template.process方法會在內(nèi)部使用這個方法進行處理。

grunt.template.setDelimiters(name)

grunt.template.addDelimiters

Lo-Dash模板添加一組命名分隔符。你或許無需使用這個方法,因為內(nèi)置的分割符應該足以滿足你的需求,但是你也可以隨時添加<% %>或者[% %]風格的分隔符。

grunt.template.addDelimiters(name, opener, closer)

幫助

grunt.template.date

使用dateformat庫格式化一個日期。

grunt.template.date(date, format)

這里有一個例子,指定的日期將被格式化為年-月-日的形式。

grunt.template.date(847602000000, 'yyyy-mm-dd') // '1996-11-10'

grunt.template.today

使用dateformat庫格式化當前日期。

grunt.template.today(format)

這里有一個例子,當前日期會被格式化為一個用4位數(shù)字表示年份的格式。

grunt.template.today('yyyy')  //'2014'

(有人提醒我每年都更新一下日期相關(guān)的信息,因此在文檔只會出現(xiàn)當前年份的日期信息)。

上一篇:快速入門下一篇:grunt.event