-requestを介してオンデマンドでアプリケーションにHandlebars
テンプレートを配信したいと考えています。サーバー上でコンパイルでき、次のような出力 ( ) を次のように配信することもできます。Ember.js
Ajax
function
String
Ember.TEMPLATES["authentication"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
this.compilerInfo = [2,'>= 1.0.0-rc.3'];
helpers = helpers || Ember.Handlebars.helpers; data = data || {};
var buffer = '', stack1, hashTypes, options, helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
data.buffer.push("<h1>Hooray! It works!</h1>\r\n");
hashTypes = {};
options = {hash:{},contexts:[depth0],types:["ID"],hashTypes:hashTypes,data:data};
data.buffer.push(escapeExpression(((stack1 = helpers.outlet),stack1 ? stack1.call(depth0, "main", options) : helperMissing.call(depth0, "outlet", "main", options))));
return buffer;
});
これはまさに、受け取ったオブジェクトString
から取得できるものです。ここで、このプリコンパイル済みテンプレートを次のようにオブジェクトJSON
に追加します。Ember.TEMPLATES
if(typeof data.template === 'string' && data.template != '') {
var escapedTemplateString =
data.template.replace(/\\n/g, "\\n").replace(/\\r/g, "\\r").replace(/\\t/g, "\\t");
Ember.TEMPLATES[templateName] = Ember.Handlebars.template(new Function(escapedTemplateString));
}
しかし、これは「文字列化された」関数全体を別の関数にラップし、anonymous function(){}
テンプレートを取得しません。で「文字列化」関数を展開するとeval
、テンプレートはundefined
...
function
「文字列化された」関数からラップアップせずに取得する方法を知っている人はいますか? 事前にお時間をいただきありがとうございます;)