2014-02-22 39 views
3

我是一個有點新的節點和JavaScript後端框架,所以請多多包涵:檣EJS但連接JS編譯車把公共模板

我一直在尋找四處打聽的前置式一個不錯的組合後端(MVC)框架與Node協同工作,目前我已決定使用SailsJS/EmberJS製作一個樣板文件,我可以隨時使用它,也可以用於未來的項目。

SailsJs(開箱即用的應用程序)使用EJS編譯後端視圖。 EmberJs(默認情況下,入門工具包)使用句柄來編譯前端視圖。

我想保留模板語言(EJS),因爲它與SailsJS的鏈接器有一個例外。它目前將公共模板編譯爲'jst.js',它們與handlebar不兼容。我想改變這個,所以'jst.js'將包含句柄編譯模板,因此它們被送到前端(燼應用程序)準備使用。

我假設爲此需要額外的節點庫。如何配置Gruntfile.js來使用該庫,以便連接器將句柄編譯模板輸出到公共目錄?

回答

0

Sails中的EJS模板與Ember的模板無關。 Ember和其他客戶端應用程序框架的關鍵方面之一是如何在客戶端完成渲染並且不再在服務器上完成渲染。除了使用Sails EJS模板將初始有效載荷傳遞給用戶外, Ember作爲REST API的風帆將最適合。至於如何處理預編譯車把模板來優化初始載荷,你可以看看Ember App Kit如何實現它。事實上,由於多種原因,EAK是一個很好的起點。

-1

您可能已經搞明白了現在,但備案...

退房https://github.com/dgeb/grunt-ember-templates爲「額外的節點庫」

,看看http://sailsjs.org/#/documentation/concepts/Assets/TaskAutomation.html?q=task-configuration關於如何配置任務。

我得到它的工作方式是在tasks\config\emberTemplates

var pipeline = require('../pipeline'); 

module.exports = function(grunt) { 

    grunt.config.set('emberTemplates', { 
     dev: { 
      compile: { 
       options: { 
        amd: true, 
        templateBasePath: pipeline.templateBasePath 
       }, 
       files: { 
        '.tmp/public/jst.js': pipeline.templateFilesToInject 
       } 
      } 
     } 
    }); 

    grunt.loadNpmTasks('grunt-ember-templates'); 
}; 

創建下列文件,並修改tasks\pipeline.js這些線

var templateBasePath = 'assets/templates/'; 
var templateFilesToInject = [ 
    templateBasePath + '**/*.hbs' //Note that whatever is replaced by '**/' will be included in the template name (necessary for defining components see http://emberjs.com/guides/components/defining-a-component/). 
]; 

module.exports.templateFilesToInject = templateFilesToInject; 
module.exports.templateBasePath = templateBasePath; 

當然,把你的模板assets/templates.hbs擴展。

0

使用grunt-ember-templates的當前版本以某種方式dev:部分不起作用。 一旦我將它剝離出來,它立刻就可以使用:

var pipeline = require('../pipeline'); 

module.exports = function(grunt) { 

grunt.config.set('emberTemplates', { 
     compile: { 
      options: { 
       amd: true, 
       templateBasePath: pipeline.templateBasePath 
      }, 
      files: { 
       '.tmp/public/jst.js': pipeline.templateFilesToInject 
      } 
     } 
}); 

grunt.loadNpmTasks('grunt-ember-templates'); 
};