app scaffold

This commit is contained in:
John Bintz 2011-04-23 19:00:22 -04:00
parent adf18ae119
commit b9c2f64d95
6 changed files with 52 additions and 0 deletions

View File

@ -91,6 +91,14 @@ class BackboneGenerator < Thor
template('app_helper.js.erb', 'public/javascripts/applications/backbone_helper.js')
end
desc 'app-scaffold', "Generate an application scaffold"
def app_scaffold
template('app_view.js.erb', 'public/javascripts/application/app_view.js')
template('app_view.jst.erb', 'app/views/application/app_view.jst')
template('controller.js.erb', 'public/javascripts/application/controller.js')
template('app_view_spec.js.erb', 'spec/javascripts/application/app_view_spec.js')
end
private
def pluralize(string)
singularize(string) + 's'

View File

@ -133,4 +133,15 @@ describe 'backbone-generator' do
File.file?(collection = 'public/javascripts/applications/backbone_helper.js').should be_true
end
end
describe 'application scaffold' do
it "should generate an application scaffold" do
system %{bin/backbone-generator app-scaffold}
File.file?(app = 'public/javascripts/application/app_view.js').should be_true
File.file?(app_view = 'app/views/application/app_view.jst').should be_true
File.file?(controller = 'public/javascripts/application/controller.js').should be_true
File.file?(spec = 'spec/javascripts/application/app_view_spec.js').should be_true
end
end
end

16
templates/app_view.js.erb Normal file
View File

@ -0,0 +1,16 @@
var AppView = Backbone.View.extend({
el: '#application',
template: JST['application/app_view'],
initialize: function() {
_.bindAll(this, 'render');
var controller = new Controller({app: this});
Backbone.history.start();
},
render: function() {
$(this.el).html(this.template());
return this;
},
});

View File

@ -0,0 +1 @@
<!-- application view goes here -->

View File

@ -0,0 +1,12 @@
describe('AppView', function() {
var app_view;
beforeEach(function() {
app_view = new AppView();
});
it('should render', function() {
expect($(app_view.render().el)).toContain('.something');
});
});

View File

@ -0,0 +1,4 @@
var Controller = Backbone.Controller.extend({
routes: {}
});