如何让node.js使用CFML风格#散列#variables?

我构build了一个Node.js框架,并且我喜欢ColdFusion的<cfoutput>风格散列限定variables。

我试图找出如何达到同样的效果。 例如:

 <h1> #this.pageTitle# </h1> <div> #this.content()# </div> 

从我在上面的主要问题留下的评论。

 /** * Load the Virtual Machine */ var vm = require('vm'); /** * Template Data */ var template = "<h1>#this.content#</h1><div>#this.sitename()#</div>"; /** * Process method */ function compile(source) { var __ = "this.__compiled = '"; /** * Replace all template tags */ __ += source.replace(/\#(.*?)\#/g, "' +$1+ '"); return __ + "';"; } /** * Create the context / scope, this can be anything from 'this', 'process' to 'require('fs')' */ var context = { content : "Robert Pitt", sitename : function(){ return "http://robertpitt.me"; } }; /** * Compile the code within the sandbox */ var compiled = vm.runInNewContext(compile(template), context); /** * Use compiled source: * value: <h1>Robert Pitt</h1><div>http://robertpitt.me</div> */ console.log(compiled); 

CoffeeScript具有string插值 :

 author = "Wittgenstein" quote = "A picture is a fact. -- #{ author }" sentence = "#{ 22 / 7 } is a decent approximation of π"