rails_backbone_generators 1.0.0 → 1.1.0

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: 69715b224d495dd52d5a944b549b4dadd3f4f6c9
4
- data.tar.gz: ea95debf6a77db53b0262ec7c9de15989ca2933f
3
+ metadata.gz: 5cfa241037e8c4eda6c3035dc229675b26dddd70
4
+ data.tar.gz: 26f12e98ffca8878650cc32fe2ed6a599a23cf85
5
5
  SHA512:
6
- metadata.gz: 6a28bed0198dc7c5ccdc66dce8f73f604179a893eb035a24ad6b353789f23c5308af2b9e0e2aa19e564bc1fde785690e54c43f185007d507a767f85dc7ee9cf9
7
- data.tar.gz: 9b4372e850bf3ff108cb814be1d1c7df5db96d4fc1b65c2e3848bb7eab3713199dfa3a88a31a8742ca986ee4cea2d7e99104e3aefe42efb6576fd73bd0430ccb
6
+ metadata.gz: 8021d2cf09cd6d89e473452d3e996a4c6c301b191f13fee5f4586ab937d57fe043dc06eb25196de528d6014c77ae23031877fe138fcf7db3a46ab1037853ca44
7
+ data.tar.gz: f63d34a06c6909c66e454cfb434526a49149f8cfd95e15205f2f83c7eb5b9ea5b9bf24d33f8b34505359f1d129f7b233a6867973210d5477c9cf55a1c7c11a53
@@ -0,0 +1,19 @@
1
+ Description:
2
+ Create a CoffeeScript Backbone Table View with templates and specs
3
+
4
+ Example:
5
+ rails generate backbone:table_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_table_view.js.coffee
12
+
13
+ app/assets/javascript/templates/thing_row.jst.eco
14
+ app/assets/javascript/templates/things_table.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_table_spec.js.coffee
@@ -0,0 +1,58 @@
1
+ module Backbone
2
+ class TableViewGenerator < 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_table_view_file
18
+ template 'table_view.js.coffee', "app/assets/javascripts/views/#{plural_file_name}_table_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_table_template_file
26
+ template 'table.jst.eco', "app/assets/javascripts/templates/#{plural_file_name}_table.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_table_view_spec_file
42
+ template 'table_view_spec.js.coffee', "spec/javascripts/views/#{plural_file_name}_table_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.<%= plural_class_name %> extends Backbone.Collection
2
+ model: <%= singular_class_name %>
@@ -0,0 +1,4 @@
1
+ describe '<%= class_name %>', ->
2
+ beforeEach ->
3
+ @sut = new <%= class_name %>
4
+
@@ -0,0 +1 @@
1
+ class window.<%= singular_class_name %> extends Backbone.Model
@@ -0,0 +1,4 @@
1
+ describe '<%= singular_class_name %>', ->
2
+ beforeEach ->
3
+ @sut = new <%= singular_class_name %>
4
+
@@ -0,0 +1,10 @@
1
+ class window.<%= singular_class_name %>RowView extends Backbone.View
2
+ template: JST['templates/<%= singular_file_name %>_row']
3
+ tagName: 'tr'
4
+
5
+ context: =>
6
+ model: @model.toJSON()
7
+
8
+ render: =>
9
+ @$el.html @template @context()
10
+ this
@@ -0,0 +1,4 @@
1
+ describe '<%= singular_class_name %>RowView', ->
2
+ beforeEach ->
3
+ @sut = new <%= singular_class_name %>RowView
4
+ @sut.render()
@@ -0,0 +1,2 @@
1
+ <table>
2
+ </table>
@@ -0,0 +1,33 @@
1
+ class window.<%= plural_class_name %>TableView extends Backbone.View
2
+ template: JST['templates/<%= plural_file_name %>_table']
3
+
4
+ initialize: =>
5
+ @views = []
6
+ @tableenTo @collection, 'add', @add_one
7
+ @tableenTo @collection, 'sync error request reset', @render
8
+ @tableenTo @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 <%= singtablear_class_name %>RowView model: model
26
+ @$('table').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 '<%= plural_class_name %>TableView', ->
2
+ beforeEach ->
3
+ @sut = new <%= plural_class_name %>TableView
4
+ @sut.render()
5
+
@@ -1,3 +1,3 @@
1
1
  module RailsBackboneGenerators
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
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: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jade Meskill
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-01 00:00:00.000000000 Z
12
+ date: 2013-11-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -61,6 +61,18 @@ files:
61
61
  - lib/generators/backbone/router/router_generator.rb
62
62
  - lib/generators/backbone/router/templates/router.js.coffee
63
63
  - lib/generators/backbone/router/templates/router_spec.js.coffee
64
+ - lib/generators/backbone/table_view/USAGE
65
+ - lib/generators/backbone/table_view/table_view_generator.rb
66
+ - lib/generators/backbone/table_view/templates/collection.js.coffee
67
+ - lib/generators/backbone/table_view/templates/collection_spec.js.coffee
68
+ - lib/generators/backbone/table_view/templates/model.js.coffee
69
+ - lib/generators/backbone/table_view/templates/model_spec.js.coffee
70
+ - lib/generators/backbone/table_view/templates/row.jst.eco
71
+ - lib/generators/backbone/table_view/templates/row_view.js.coffee
72
+ - lib/generators/backbone/table_view/templates/row_view_spec.js.coffee
73
+ - lib/generators/backbone/table_view/templates/table.jst.eco
74
+ - lib/generators/backbone/table_view/templates/table_view.js.coffee
75
+ - lib/generators/backbone/table_view/templates/table_view_spec.js.coffee
64
76
  - lib/generators/backbone/view/USAGE
65
77
  - lib/generators/backbone/view/templates/template.jst.eco
66
78
  - lib/generators/backbone/view/templates/view.js.coffee