rails_backbone_generators 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c00bfb328f4282ad26dd62a088d1bdffcbed9bef
4
- data.tar.gz: a94928e125c0b1af245ee88535d84b8267bc0734
3
+ metadata.gz: 0206540e03aa2afc036092a75cb1318733712704
4
+ data.tar.gz: 0ab6bef5c2d6edb59b0ed5adc3ed8feddec7ce85
5
5
  SHA512:
6
- metadata.gz: 271dca8bc22d69666182c52c8812edcdf5f95447aabce4632844eafddd205c58c27f394635f8215b54ca7f2807c313d64f80c4d4ca53fe5b572985aad55dbdc1
7
- data.tar.gz: 1f2bd21fc928813bf525857e2d219c6baa0aaca32e68037ec2497507c765ac27a59e2812db8607323a2971caa22286d732da56b686260bad812a5c4a35580c74
6
+ metadata.gz: 0361871c6abc7f38f6ab877d0b76afe47b44a4b2a67fc42e431ccdd5f798a85c177e9a7bfd36f6898afccc306901ea045697a85062e2c2952f3b05464082058e
7
+ data.tar.gz: fbd3183b299d45348004e433a4ad94c7db225c6aefb77034da9cac68aabf549e28e951a37f14c2f2b1556dd1246385191a488bd1239e3be95f834299e6421d72
@@ -2,22 +2,22 @@ module Backbone
2
2
  class CollectionGenerator < Rails::Generators::NamedBase
3
3
  source_root File.expand_path('../templates', __FILE__)
4
4
 
5
- def copy_collection_file
6
- template 'collection.js.coffee', "app/assets/javascripts/collections/#{plural_file_name}.js.coffee"
7
- end
8
-
9
5
  def copy_model_file
10
6
  template 'model.js.coffee', "app/assets/javascripts/models/#{singular_file_name}.js.coffee"
11
7
  end
12
8
 
13
- def copy_spec_file
14
- template 'collection_spec.js.coffee', "spec/javascripts/collections/#{plural_file_name}_spec.js.coffee"
9
+ def copy_collection_file
10
+ template 'collection.js.coffee', "app/assets/javascripts/collections/#{plural_file_name}.js.coffee"
15
11
  end
16
12
 
17
13
  def copy_model_spec_file
18
14
  template 'model_spec.js.coffee', "spec/javascripts/models/#{singular_file_name}_spec.js.coffee"
19
15
  end
20
16
 
17
+ def copy_spec_file
18
+ template 'collection_spec.js.coffee', "spec/javascripts/collections/#{plural_file_name}_spec.js.coffee"
19
+ end
20
+
21
21
  protected
22
22
  def singular_file_name
23
23
  @singular_file_name ||= file_name.singularize
@@ -0,0 +1,19 @@
1
+ Description:
2
+ Create a CoffeeScript Backbone List View with templates and specs
3
+
4
+ Example:
5
+ rails generate backbone:list_view thing
6
+
7
+ This will create:
8
+ app/assets/javascript/models/thing.js.coffee
9
+ app/assets/javascript/collections/things.js.coffee
10
+ app/assets/javascript/views/thing_row_view.js.coffee
11
+ app/assets/javascript/views/things_list_view.js.coffee
12
+
13
+ app/assets/javascript/templates/thing_row.jst.eco
14
+ app/assets/javascript/templates/things_list.jst.eco
15
+
16
+ spec/javascript/models/thing_spec.js.coffee
17
+ spec/javascript/collections/things_spec.js.coffee
18
+ spec/javascript/views/thing_row_spec.js.coffee
19
+ spec/javascript/views/things_list_spec.js.coffee
@@ -0,0 +1,58 @@
1
+ module Backbone
2
+ class ListViewGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def copy_model_file
6
+ template 'model.js.coffee', "app/assets/javascripts/models/#{singular_file_name}.js.coffee"
7
+ end
8
+
9
+ def copy_collection_file
10
+ template 'collection.js.coffee', "app/assets/javascripts/collections/#{plural_file_name}.js.coffee"
11
+ end
12
+
13
+ def copy_row_view_file
14
+ template 'row_view.js.coffee', "app/assets/javascripts/views/#{singular_file_name}_row_view.js.coffee"
15
+ end
16
+
17
+ def copy_list_view_file
18
+ template 'list_view.js.coffee', "app/assets/javascripts/views/#{plural_file_name}_list_view.js.coffee"
19
+ end
20
+
21
+ def copy_row_template_file
22
+ template 'row.jst.eco', "app/assets/javascripts/templates/#{singular_file_name}_row.jst.eco"
23
+ end
24
+
25
+ def copy_list_template_file
26
+ template 'list.jst.eco', "app/assets/javascripts/templates/#{plural_file_name}_list.jst.eco"
27
+ end
28
+
29
+ def copy_model_spec_file
30
+ template 'model_spec.js.coffee', "spec/javascripts/models/#{singular_file_name}_spec.js.coffee"
31
+ end
32
+
33
+ def copy_collection_spec_file
34
+ template 'collection_spec.js.coffee', "spec/javascripts/collections/#{plural_file_name}_spec.js.coffee"
35
+ end
36
+
37
+ def copy_row_view_spec_file
38
+ template 'row_view_spec.js.coffee', "spec/javascripts/views/#{singular_file_name}_row_view_spec.js.coffee"
39
+ end
40
+
41
+ def copy_list_view_spec_file
42
+ template 'list_view_spec.js.coffee', "spec/javascripts/views/#{plural_file_name}_list_view_spec.js.coffee"
43
+ end
44
+
45
+ protected
46
+ def plural_class_name
47
+ @plural_class_name ||= class_name.pluralize
48
+ end
49
+
50
+ def singular_class_name
51
+ @singular_class_name ||= class_name.singularize
52
+ end
53
+
54
+ def singular_file_name
55
+ @singular_file_name ||= file_name.singularize
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ class window.<%= class_name.pluralize %> extends Backbone.Collection
2
+ model: <%= class_name.singularize %>
@@ -0,0 +1,4 @@
1
+ describe '<%= class_name %>', ->
2
+ beforeEach ->
3
+ @sut = new <%= class_name %>
4
+
@@ -0,0 +1,33 @@
1
+ class window.<%= plural_class_name %>ListView extends Backbone.View
2
+ template: JST['templates/<%= plural_file_name %>_list']
3
+
4
+ initialize: =>
5
+ @views = []
6
+ @listenTo @collection, 'add', @add_one
7
+ @listenTo @collection, 'sync error request reset', @render
8
+ @listenTo @collection, 'search', @render
9
+
10
+ context: =>
11
+ loading: @collection.loading
12
+
13
+ render: =>
14
+ @$el.html @template @context()
15
+ @remove_views()
16
+ @collection.each @add_one
17
+ this
18
+
19
+ remove: =>
20
+ @remove_views()
21
+ super
22
+
23
+ # Instance Methods
24
+ add_one: (model) =>
25
+ view = new <%= singular_class_name %>RowView model: model
26
+ @$('ul').append view.render().$el
27
+ @views.push view
28
+
29
+ remove_views: =>
30
+ _.each @views, (view) =>
31
+ view.remove()
32
+
33
+ @views = []
@@ -0,0 +1,5 @@
1
+ describe '<%= class_name %>View', ->
2
+ beforeEach ->
3
+ @sut = new <%= class_name %>View
4
+ @sut.render()
5
+
@@ -0,0 +1 @@
1
+ class window.<%= class_name %> extends Backbone.Model
@@ -0,0 +1,4 @@
1
+ describe '<%= class_name %>', ->
2
+ beforeEach ->
3
+ @sut = new <%= class_name %>
4
+
@@ -0,0 +1,9 @@
1
+ class window.<%= singular_class_name %>RowView extends Backbone.View
2
+ template: JST['templates/<%= singular_file_name %>_row']
3
+ tagName: 'li'
4
+
5
+ context: =>
6
+ model: @model.toJSON()
7
+
8
+ render: =>
9
+ @$el.html @template @context()
@@ -0,0 +1,5 @@
1
+ describe '<%= class_name %>View', ->
2
+ beforeEach ->
3
+ @sut = new <%= class_name %>View
4
+ @sut.render()
5
+
@@ -1,3 +1,3 @@
1
1
  module RailsBackboneGenerators
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_backbone_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jade Meskill
@@ -41,6 +41,18 @@ files:
41
41
  - lib/generators/backbone/collection/templates/collection_spec.js.coffee
42
42
  - lib/generators/backbone/collection/templates/model.js.coffee
43
43
  - lib/generators/backbone/collection/templates/model_spec.js.coffee
44
+ - lib/generators/backbone/list_view/USAGE
45
+ - lib/generators/backbone/list_view/list_view_generator.rb
46
+ - lib/generators/backbone/list_view/templates/collection.js.coffee
47
+ - lib/generators/backbone/list_view/templates/collection_spec.js.coffee
48
+ - lib/generators/backbone/list_view/templates/list.jst.eco
49
+ - lib/generators/backbone/list_view/templates/list_view.js.coffee
50
+ - lib/generators/backbone/list_view/templates/list_view_spec.js.coffee
51
+ - lib/generators/backbone/list_view/templates/model.js.coffee
52
+ - lib/generators/backbone/list_view/templates/model_spec.js.coffee
53
+ - lib/generators/backbone/list_view/templates/row.jst.eco
54
+ - lib/generators/backbone/list_view/templates/row_view.js.coffee
55
+ - lib/generators/backbone/list_view/templates/row_view_spec.js.coffee
44
56
  - lib/generators/backbone/model/USAGE
45
57
  - lib/generators/backbone/model/model_generator.rb
46
58
  - lib/generators/backbone/model/templates/model.js.coffee