more small changes

This commit is contained in:
John Bintz 2011-04-15 15:02:36 -04:00
parent cfa1fbe2bf
commit 6469fd7fa7
5 changed files with 38 additions and 10 deletions

28
README.md Normal file
View File

@ -0,0 +1,28 @@
*Not done yet!*
Currently only works with Rails-ish projects and with Jasmine & Jammit. I'm selfish.
### Models
`backbone-generate model Admin::User` creates an AdminUserModel object in:
* `public/javascripts/models/admin/user.js`
* `spec/javascripts/models/admin/user_spec.js`
### View
`backbone-generate view Admin::User` creates an AdminUserView object in:
* `public/javascripts/views/admin/user.js`
* `spec/javascripts/views/admin/user_spec.js`
* `app/views/admin/user.jst`
### Collection
`backbone-generate collection Admin::User` creates an AdminUsersCollection object in:
* `public/javascripts/collections/admin/users.js`
* `spec/javascripts/collections/admin/users_spec.js`
Please add more and make it more friendly with things that are not Rails, Jasmine, and Jammit!

View File

@ -39,8 +39,8 @@ class BackboneGenerator < Thor
desc 'collection Namespaced::Name', "Create a collection" desc 'collection Namespaced::Name', "Create a collection"
def collection(name) def collection(name)
@name = name @name = name
template('collection.js.erb', "public/javascripts/collections/#{underscore_name}.js") template('collection.js.erb', "public/javascripts/collections/#{underscore_name}s.js")
template('collection_spec.js.erb', "spec/javascripts/collections/#{underscore_name}_spec.js") template('collection_spec.js.erb', "spec/javascripts/collections/#{underscore_name}s_spec.js")
end end
end end

View File

@ -41,12 +41,12 @@ describe 'backbone-generator' do
it "should generate the collection files" do it "should generate the collection files" do
system %{bin/backbone-generator collection Section::Collection} system %{bin/backbone-generator collection Section::Collection}
File.file?(collection = 'public/javascripts/collections/section/collection.js').should be_true File.file?(collection = 'public/javascripts/collections/section/collections.js').should be_true
File.file?(spec = 'spec/javascripts/collections/section/collection_spec.js').should be_true File.file?(spec = 'spec/javascripts/collections/section/collections_spec.js').should be_true
File.read(collection).should match(/SectionCollection/) File.read(collection).should match(/SectionCollectionsCollection/)
File.read(collection).should match(%r{section/collection}) File.read(collection).should match(%r{section/collection})
File.read(spec).should match(/SectionCollection/) File.read(spec).should match(/SectionCollectionsCollection/)
end end
end end
end end

View File

@ -1,3 +1,3 @@
var <%= object_name %>Collection = Backbone.Collection.extend({ var <%= object_name %>sCollection = Backbone.Collection.extend({
url: '/<%= underscore_name %>' url: '/<%= underscore_name %>'
}); });

View File

@ -1,4 +1,4 @@
describe('<%= object_name %>Collection', function() { describe('<%= object_name %>sCollection', function() {
var collection, server; var collection, server;
beforeEach(function() { beforeEach(function() {
@ -10,7 +10,7 @@ describe('<%= object_name %>Collection', function() {
}); });
it('should fetch records from the API', function() { it('should fetch records from the API', function() {
collection = new <%= object_name %>Collection(); collection = new <%= object_name %>sCollection();
server.respondWith('GET', '<%= underscore_name %>', [ 200, { 'Content-type': 'application/json' }, "[{id: 1}]" ]); server.respondWith('GET', '<%= underscore_name %>', [ 200, { 'Content-type': 'application/json' }, "[{id: 1}]" ]);
collection.fetch() collection.fetch()
@ -18,4 +18,4 @@ describe('<%= object_name %>Collection', function() {
expect(collection.length).toEqual(1); expect(collection.length).toEqual(1);
}); });
}); }s);