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 +4 -4
- data/lib/generators/backbone/collection/collection_generator.rb +6 -6
- data/lib/generators/backbone/list_view/USAGE +19 -0
- data/lib/generators/backbone/list_view/list_view_generator.rb +58 -0
- data/lib/generators/backbone/list_view/templates/collection.js.coffee +2 -0
- data/lib/generators/backbone/list_view/templates/collection_spec.js.coffee +4 -0
- data/lib/generators/backbone/list_view/templates/list.jst.eco +2 -0
- data/lib/generators/backbone/list_view/templates/list_view.js.coffee +33 -0
- data/lib/generators/backbone/list_view/templates/list_view_spec.js.coffee +5 -0
- data/lib/generators/backbone/list_view/templates/model.js.coffee +1 -0
- data/lib/generators/backbone/list_view/templates/model_spec.js.coffee +4 -0
- data/lib/generators/backbone/list_view/templates/row.jst.eco +0 -0
- data/lib/generators/backbone/list_view/templates/row_view.js.coffee +9 -0
- data/lib/generators/backbone/list_view/templates/row_view_spec.js.coffee +5 -0
- data/lib/rails_backbone_generators.rb +1 -1
- metadata +13 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0206540e03aa2afc036092a75cb1318733712704
|
4
|
+
data.tar.gz: 0ab6bef5c2d6edb59b0ed5adc3ed8feddec7ce85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
14
|
-
template '
|
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,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 @@
|
|
1
|
+
class window.<%= class_name %> extends Backbone.Model
|
File without changes
|
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.
|
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
|