diff --git a/bin/backbone-generator b/bin/backbone-generator index e57a729..2367eed 100755 --- a/bin/backbone-generator +++ b/bin/backbone-generator @@ -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' diff --git a/spec/bin/backbone-generator_spec.rb b/spec/bin/backbone-generator_spec.rb index 14cae1b..a15e5c5 100644 --- a/spec/bin/backbone-generator_spec.rb +++ b/spec/bin/backbone-generator_spec.rb @@ -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 diff --git a/templates/app_view.js.erb b/templates/app_view.js.erb new file mode 100644 index 0000000..9f1dd1a --- /dev/null +++ b/templates/app_view.js.erb @@ -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; + }, +}); + diff --git a/templates/app_view.jst.erb b/templates/app_view.jst.erb new file mode 100644 index 0000000..22ec691 --- /dev/null +++ b/templates/app_view.jst.erb @@ -0,0 +1 @@ + diff --git a/templates/app_view_spec.js.erb b/templates/app_view_spec.js.erb new file mode 100644 index 0000000..331fe6f --- /dev/null +++ b/templates/app_view_spec.js.erb @@ -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'); + }); +}); + diff --git a/templates/controller.js.erb b/templates/controller.js.erb new file mode 100644 index 0000000..14fe57d --- /dev/null +++ b/templates/controller.js.erb @@ -0,0 +1,4 @@ +var Controller = Backbone.Controller.extend({ + routes: {} +}); +