Skip to content

Instantly share code, notes, and snippets.

@chonthu
Forked from mitsuruog/Gruntfile.js
Created June 26, 2013 16:26
Show Gist options
  • Save chonthu/5868940 to your computer and use it in GitHub Desktop.
Save chonthu/5868940 to your computer and use it in GitHub Desktop.
app
├ Gruntfile.js
├ hbs
│ └ partial.hbs //テンプレート
└ js
├ views
│ └ partial.js //テンプレートをレンダリングするView
├ collections
├ models
├ template.js //テンプレートがプリコンパイルされたJS
├ namespace.js
  └ app.js
module.exports = function(grunt) {
grunt.initConfig({
//some...
handlebars: {
compile: {
options: {
namespace: "MyApp.Templates",
processName: function(filepath) { // input -> app/hbs/partial.hbs
var pieces = filepath.split("/");
return pieces[pieces.length - 1].replace(/.hbs$/ , ''); //output -> partial
}
},
files: {
"app/js/template.js": "app/hbs/*.hbs"
}
}
}
});
// Load the plugin.
//some tasks...
grunt.loadNpmTasks('grunt-contrib-handlebars');
// Default task(s).
grunt.registerTask('default', ['handlebars']);
};
var MyApp = {
Views: {},
Collections: {},
Models: {},
Templates: {}
}
{{#each models}}
<ul>
<li class="id">{{this.id}}</li>
<li class="name">({{this.name}})</li>
</ul>
{{/each}}
MyApp.Views.partial = Backbone.View.extend({
//partial.hbsで定義したテンプレート
tmpl: MyApp.Templates.partial,
//some...
render: function() {
this.$el.html(
this.tmpl({
models: this.collection.toJSON()
})
);
},
//some...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment