2012-02-26 91 views
1

我想在早午餐中使用鬍子模板。這是我的config.coffee文件:如何讓鬍子模板在早午餐中工作

{languages, plugins} = require 'brunch-extensions' 

# Make config loadable via require() for brunch. 
exports.config = 
    # Available plugins: 
    # * AssetsPlugin: copy `app/assets` contents to `build/` 
    plugins: [plugins.AssetsPlugin] 

    # Contains a list of output filenames that your application would generate. 
    # Format: 
    # 
    # 'filename': 
    # languages: 
    #  'regExp, with which input files will be matched': language class 
    # order: 
    #  before: [files, that would be loaded before anything else] 
    #  after: [files, that would be loaded after anything else] 
    # 
    files: 
    'scripts/app.js': 
     languages: 
     '\.js$': languages.JavaScriptLanguage 
     '\.coffee$': languages.CoffeeScriptLanguage 
     '\.eco$': languages.EcoLanguage 
     '\.mustache$': languages.HoganLanguage 
     order: 
     before: [ 
      'vendor/scripts/console-helper.js' 
      'vendor/scripts/jquery-1.7.js' 
      'vendor/scripts/underscore-1.1.7.js' 
      'vendor/scripts/backbone-0.5.3.js' 
     ] 

    'styles/app.css': 
     languages: 
     '\.css$': languages.CSSLanguage 
     '\.styl$': languages.StylusLanguage 
     order: 
     before: ['vendor/styles/normalize.css'] 
     after: ['vendor/styles/helpers.css'] 

但開始brunch watch,當我得到了以下錯誤:

[17:27:45]: [Brunch]: cannot parse config entry 
config.files['scripts/app.js'].languages['.mustache$']: TypeError: undefined is not a function. 
+0

您能否解決這個問題 – jsf 2012-02-27 02:26:58

+0

不是。看起來他們放棄了鬍鬚支持,因爲我在語言文件夾中找不到任何參考。 – 2012-02-27 07:39:27

回答

1

事實上,它似乎有在早午餐的擴展0.2.2沒有鬍子的支持。你可以做的是直接從主分支安裝早午餐的擴展:

npm install https://github.com/brunch/brunch-extensions/tarball/master 

或者你也可以添加自己的HoganLanguage,從their github

hogan = require 'hogan.js' 
{BaseLanguage} = require './base' 

# Requires Hogan 1.0.4 
# 
# Example: 
# $(@el).html(template.render name: "mdp", city: "SF") 
class exports.HoganLanguage extends BaseLanguage 
    compile: (path, callback) -> 
    @readFile path, (error, data) => 
     return callback error if error? 
     try 
     content = hogan.compile data, asString: yes 
     callback null, "exports.render = function(data) { 
      var t = new Hogan.Template(); 
      t.r = #{content}; 
      return t.render(data); 
     }" 
     catch error 
     callback error 

它應該可以正常工作,如果你只是安裝hogan.js並在上面更改爲{BaseLanguage} = require 'brunch-extensions/lib/languages/base'

+0

我被告知需要將brunch-extensions升級到0.3,它應該可以工作。今晚會這樣做。 – jsf 2012-02-27 20:36:44