From d3cbfd9be2e441d3c4ce207ceb1dc4ec287dcd4a Mon Sep 17 00:00:00 2001 From: John Bintz Date: Sat, 16 Apr 2011 10:39:18 -0400 Subject: [PATCH] more granularity in the view generation, match rails better --- bin/backbone-generator | 4 ++-- spec/bin/backbone-generator_spec.rb | 8 ++++---- templates/collection_view.js.erb | 2 +- templates/view.js.erb | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bin/backbone-generator b/bin/backbone-generator index e7dd806..dc56927 100755 --- a/bin/backbone-generator +++ b/bin/backbone-generator @@ -27,7 +27,7 @@ class BackboneGenerator < Thor def generate_view template('view.js.erb', "public/javascripts/views/#{underscore_name}_view.js") - template('view.jst.erb', "app/views/#{underscore_name}.jst") + template('view.jst.erb', "app/views/#{underscore_name}s/view.jst") template('view_spec.js.erb', "spec/javascripts/views/#{underscore_name}_view_spec.js") end @@ -38,7 +38,7 @@ class BackboneGenerator < Thor def generate_collection_view template('collection_view.js.erb', "public/javascripts/views/#{underscore_name}s_view.js") - template('collection_view.jst.erb', "app/views/#{underscore_name}s.jst") + template('collection_view.jst.erb', "app/views/#{underscore_name}s/list.jst") template('collection_view_spec.js.erb', "spec/javascripts/views/#{underscore_name}s_view_spec.js") end end diff --git a/spec/bin/backbone-generator_spec.rb b/spec/bin/backbone-generator_spec.rb index 10480c7..0914244 100644 --- a/spec/bin/backbone-generator_spec.rb +++ b/spec/bin/backbone-generator_spec.rb @@ -22,11 +22,11 @@ describe 'backbone-generator' do def should_generate_view File.file?(view = 'public/javascripts/views/section/model_view.js').should be_true File.file?(spec = 'spec/javascripts/views/section/model_view_spec.js').should be_true - File.file?(template = 'app/views/section/model.jst').should be_true + File.file?(template = 'app/views/section/models/view.jst').should be_true File.read(view).should match(/SectionModel/) File.read(view).should match(/return this/) - File.read(view).should match(%r{template: JST\['section/model'\]}) + File.read(view).should match(%r{template: JST\['section/models/view'\]}) File.read(spec).should match(/SectionModel/) end @@ -42,12 +42,12 @@ describe 'backbone-generator' do def should_generate_collection_view File.file?(view = 'public/javascripts/views/section/models_view.js').should be_true File.file?(spec = 'spec/javascripts/views/section/models_view_spec.js').should be_true - File.file?(template = 'app/views/section/models.jst').should be_true + File.file?(template = 'app/views/section/models/list.jst').should be_true File.read(view).should match(/SectionModelsView/) File.read(view).should match(/SectionModelView/) File.read(view).should match(/return this/) - File.read(view).should match(%r{template: JST\['section/models'\]}) + File.read(view).should match(%r{template: JST\['section/models/list'\]}) File.read(spec).should match(/SectionModelsView/) end diff --git a/templates/collection_view.js.erb b/templates/collection_view.js.erb index 5d63862..aadedb9 100644 --- a/templates/collection_view.js.erb +++ b/templates/collection_view.js.erb @@ -1,5 +1,5 @@ var <%= object_name %>sView = Backbone.View.extend({ - template: JST['<%= underscore_name %>s'], + template: JST['<%= underscore_name %>s/list'], initialize: function(collection) { _.bindAll(this, 'render', 'addOne', 'addAll'); diff --git a/templates/view.js.erb b/templates/view.js.erb index 4994d91..76d1990 100644 --- a/templates/view.js.erb +++ b/templates/view.js.erb @@ -1,5 +1,5 @@ var <%= object_name %>View = Backbone.View.extend({ - template: JST['<%= underscore_name %>'], + template: JST['<%= underscore_name %>s/view'], initialize: function() { _.bindAll(this, 'render'); },