Hogan.jsは、Twitterで開発されたJavaScriptテンプレートエンジンです。2.5KBと軽量でシンプルな仕組みとなっています。Matadorで使われています。
「hogan」ではなく「Hogan.js」です。npm install時に注意。地味にハマりました。
$ npm install hogan.js npm http GET https://registry.npmjs.org/hogan.js npm http 304 https://registry.npmjs.org/hogan.js hogan.js@2.0.0 ../node_modules/hogan.js
sample.coffee
hogan = require 'hogan.js'
template = hogan.compile "@{{name}}"
names = ['初音ミク', '鈴音リン', '鈴音レン']
names.map (vocaloid) ->
template.render({name:vocaloid})
console.log 'VOCALOID: ' + names.join(' ') + '!'
実行
$ coffee sample.coffee VOCALOID: 初音ミク 鈴音リン 鈴音レン!
{{hogehoge}} に template.render 関数で指定したオブジェクトのhogehogeキーの値が入ってきます。
0 件のコメント:
コメントを投稿