(この質問はこれに関連していますが、今ではgrunt-ember-templates
代わりに移動しましたgrunt-contrib-handlebars
)
コードベースをより管理しやすくするために、ember.js ハンドルバー テンプレートをいくつかのファイルに分割しようとしています。私はgrunt-ember-templates
次のように構成されたを使用しています:
ember_templates: {
compile: {
options: {
templateName: function(sourceFile) {
return sourceFile.replace(/app\/templates\//, ''); // <%= yeoman.dist %>/scripts/
}
},
files: {
'<%= yeoman.dist %>/scripts/templates.js': [
'<%= yeoman.app %>/templates/**/*.hbs'
]
}
}
}
これによりdist/scripts/templates.js
、クライアントが喜んでロードしている期待どおりの が作成されます。は次のtemplates.js
ようになります。
Ember.TEMPLATES["accounts"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
...
これは私には問題ないようです。テンプレートはEmber.TEMPLATES
、予想されるキーとともに配列に保存されます。生成されたファイルapplication
のさらに下には、キーもあります。templates.js
Ember.TEMPLATES["application"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
から来ていtemplates/application.hbs
ます:
<section class="toolbar">
</section>
<section class="main_section">
<nav>
...
</nav>
{{ outlet }}
</section>
<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
...
</div>
それでも、 がロードされたときにこのエラーが発生しますtemplates.js
(これは実際には 内に埋め込まれていscripts.js
ます。以下の my を参照してくださいindex.html
):
Uncaught Error: assertion failed: You specified the templateName application for <App.ApplicationView:ember312>, but it did not exist.
この重大なエラーは何を意味し、どうすればそれを取り除くことができますか?
これは私のEmber Application
です:
this.App = Ember.Application.create({
LOG_TRANSITIONS: true,
VERSION: '1.0.0',
ready: function () {
console.log('App version: ' + App.VERSION + ' is ready.');
}
});
これは私のApplicationView
です:
App.ApplicationView = Ember.View.extend({
templateName: 'application'
});
これは私のindex.html
です:
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<title></title>
<meta name="description" content=""/>
<meta name="viewport" content="width=device-width"/>
<!-- build:css styles/main.css -->
<link rel="stylesheet" href="styles/bootstrap.min.css"/>
<link rel="stylesheet" href="styles/css/font-awesome.min.css"/>
<link rel="stylesheet" href="styles/font-styles.css"/>
<link rel="stylesheet" href="styles/main.css"/>
<!-- endbuild -->
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
<![endif]-->
<!-- Add your site or application content here -->
<!-- My templates used to be here, but now they are in templates.js -->
<div class="pagination">
<ul>
<li><a href="#">Prev</a></li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">Next</a></li>
</ul>
</div>
</script>
<!-- build:js scripts/scripts.js -->
<script src="scripts/vendor/jquery-1.9.1.js"></script>
<script src="scripts/vendor/handlebars.1.0.rc.3.js"></script>
<script src="scripts/vendor/ember-1.0.0-rc.2.js"></script>
<script src="scripts/vendor/ember-data.js"></script>
<script src="scripts/vendor/bootstrap.min.js"></script>
<script src="scripts/templates.js"></script>
<script src="scripts/main.js"></script>
<!-- endbuild -->
</body>
</html>