rails_backbone_generators 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Create a CoffeeScript Backbone Selector with templates
3
+
4
+ Example:
5
+
6
+ In this example, you can select projects to add and remove from users and the relationship will be called project users
7
+
8
+ rails generate backbone:selector <relationship> <receiver> <emitter>
9
+ rails generate backbone:selector project_users user projects
10
+
11
+
@@ -0,0 +1,90 @@
1
+ module Backbone
2
+ class SelectorGenerator < Rails::Generators::NamedBase
3
+ argument :receiver, :type => :string
4
+ argument :emittor, :type => :string
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_collection_files
8
+ template 'collection.js.coffee', "app/assets/javascripts/collections/#{plural_file_name}.js.coffee"
9
+ end
10
+
11
+ def copy_list_view_files
12
+ template 'list_view.js.coffee', "app/assets/javascripts/views/#{plural_file_name}_selector_list_view.js.coffee"
13
+ template 'list.jst.eco', "app/assets/javascripts/templates/#{plural_file_name}_selector_list.jst.eco"
14
+ end
15
+
16
+ def copy_model_files
17
+ template 'receiver_model.js.coffee', "app/assets/javascripts/models/#{singular_receiver_file_name}.js.coffee"
18
+ template 'model.js.coffee', "app/assets/javascripts/models/#{singular_file_name}.js.coffee"
19
+ end
20
+
21
+ def router
22
+ template 'router.js.coffee', "app/assets/javascripts/routers/#{plural_file_name}_selector_router.js.coffee"
23
+ end
24
+
25
+ def copy_row_view_files
26
+ template 'row_view.js.coffee', "app/assets/javascripts/views/#{singular_file_name}_selector_row_view.js.coffee"
27
+ template 'row.jst.eco', "app/assets/javascripts/templates/#{singular_file_name}_selector_row.jst.eco"
28
+ end
29
+
30
+ def copy_view
31
+ template 'view.js.coffee', "app/assets/javascripts/views/#{plural_file_name}_selector_view.js.coffee"
32
+ template 'template.jst.eco', "app/assets/javascripts/templates/#{plural_file_name}_selector.jst.eco"
33
+ end
34
+
35
+ protected
36
+
37
+ def emittor_file_name
38
+ @emittor_file_name ||= parse_file_name emittor
39
+ end
40
+
41
+ def human_name
42
+ plural_file_name.humanize.titleize
43
+ end
44
+
45
+ def plural_class_name
46
+ @plural_class_name ||= class_name.pluralize
47
+ end
48
+
49
+ def plural_receiver_file_name
50
+ @plural_receiver_file_name ||= singular_receiver_file_name.pluralize
51
+ end
52
+
53
+ def plural_emittor_file_name
54
+ @plural_emittor_file_name ||= singular_emittor_file_name.pluralize
55
+ end
56
+
57
+ def singular_class_name
58
+ @singular_class_name ||= class_name.singularize
59
+ end
60
+
61
+ def singular_emittor_class_name
62
+ @singular_emittor_class_name ||= emittor_file_name.classify.singularize
63
+ end
64
+
65
+ def singular_file_name
66
+ @singular_file_name ||= file_name.singularize
67
+ end
68
+
69
+ def singular_receiver_class_name
70
+ @singular_receiver_class_name ||= receiver_file_name.classify.singularize
71
+ end
72
+
73
+ def singular_emittor_file_name
74
+ @singular_emittor_file_name ||= emittor_file_name.singularize
75
+ end
76
+
77
+ def singular_receiver_file_name
78
+ @singular_receiver_file_name ||= receiver_file_name.singularize
79
+ end
80
+
81
+ def receiver_file_name
82
+ @receiver_file_name ||= parse_file_name receiver
83
+ end
84
+
85
+ def parse_file_name(name)
86
+ class_path = name.include?('/') ? name.split('/') : name.split('::')
87
+ class_path.last.underscore
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,3 @@
1
+ class window.<%= plural_class_name %> extends Backbone.Collection
2
+ model: <%= singular_class_name %>
3
+ url: '/api/v2/<%= plural_file_name %>'
@@ -0,0 +1,4 @@
1
+ describe '<%= class_name %>', ->
2
+ beforeEach ->
3
+ @sut = new <%= class_name %>
4
+
@@ -0,0 +1,2 @@
1
+ <ul class="nav nav-tabs nav-stacked">
2
+ </ul>
@@ -0,0 +1,32 @@
1
+ class window.<%= plural_class_name %>SelectorListView extends Backbone.View
2
+ template: JST['templates/<%= plural_file_name %>_selector_list']
3
+
4
+ initialize: =>
5
+ @views = []
6
+ @listenTo @collection, 'add', @add_one
7
+ @listenTo @collection, 'sync error request reset', @render
8
+
9
+ context: =>
10
+ loading: @collection.loading
11
+
12
+ render: =>
13
+ @$el.html @template @context()
14
+ @remove_views()
15
+ @collection.each @add_one
16
+ this
17
+
18
+ remove: =>
19
+ @remove_views()
20
+ super
21
+
22
+ # Instance Methods
23
+ add_one: (model) =>
24
+ view = new <%= singular_class_name %>SelectorRowView model: model
25
+ @$('ul').append view.render().$el
26
+ @views.push view
27
+
28
+ remove_views: =>
29
+ _.each @views, (view) =>
30
+ view.remove()
31
+
32
+ @views = []
@@ -0,0 +1,5 @@
1
+ describe '<%= plural_class_name %>ListView', ->
2
+ beforeEach ->
3
+ @sut = new <%= plural_class_name %>ListView
4
+ @sut.render()
5
+
@@ -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,16 @@
1
+ class window.<%= singular_receiver_class_name %> extends Backbone.Model
2
+ urlRoot: '/api/v2/<%= plural_receiver_file_name %>'
3
+ initialize: =>
4
+ @available_<%= plural_file_name %> = new <%= plural_class_name %> @get 'available_<%= plural_file_name %>'
5
+ @on 'change:available_<%= plural_file_name %>', => @available_<%= plural_file_name %>.set @get 'available_<%= plural_file_name %>'
6
+
7
+ @<%= plural_file_name %> = new <%= plural_class_name %> @get '<%= plural_file_name %>'
8
+ @on 'change:<%= plural_file_name %>', => @<%= plural_file_name %>.set @get '<%= plural_file_name %>'
9
+
10
+ @listenTo @available_<%= plural_file_name %>, 'destroy', (model) =>
11
+ @<%= plural_file_name %>.create model.clone()
12
+
13
+ @listenTo @<%= plural_file_name %>, 'destroy', (model) =>
14
+ model.unset 'id'
15
+ @available_<%= plural_file_name %>.add model.clone()
16
+
@@ -0,0 +1,11 @@
1
+ class <%= class_name %>SelectorRouter extends Backbone.Router
2
+ routes:
3
+ '<%= plural_receiver_file_name %>/:<%= singular_receiver_file_name %>_id/<%= plural_emittor_file_name %>': '<%= singular_receiver_file_name %>_<%= plural_emittor_file_name %>'
4
+
5
+ <%= singular_receiver_file_name %>_<%= plural_emittor_file_name %>: (<%= singular_receiver_file_name %>_id) =>
6
+ model = new <%= singular_receiver_class_name %> id: <%= singular_receiver_file_name %>_id
7
+ model.fetch()
8
+ view = new <%= plural_class_name %>SelectorView model: model
9
+ $('.main-content').html view.render().$el
10
+
11
+ new <%= class_name %>SelectorRouter
@@ -0,0 +1,3 @@
1
+ <a href="#">
2
+ <%%= @model.<%= singular_emittor_file_name %>_name %>
3
+ </a>
@@ -0,0 +1,23 @@
1
+ class window.<%= singular_class_name %>SelectorRowView extends Backbone.View
2
+ template: JST['templates/<%= singular_file_name %>_selector_row']
3
+ tagName: 'li'
4
+
5
+ initialize: =>
6
+ @listenTo @model, 'remove', @remove
7
+ @listenTo @model, 'change', @render
8
+
9
+ context: =>
10
+ model: @model.toJSON()
11
+
12
+ render: =>
13
+ @$el.html @template @context()
14
+ this
15
+
16
+ events: =>
17
+ 'click': 'click'
18
+
19
+ click: ($event) =>
20
+ $event.preventDefault()
21
+ $event.stopPropagation()
22
+
23
+ @model.destroy()
@@ -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,7 @@
1
+ <h1><%= human_name %></h1>
2
+
3
+ <h2>Existing <%= human_name %></h2>
4
+ <div class="existing"></div>
5
+
6
+ <h2>Available <%= human_name %></h2>
7
+ <div class="available"></div>
@@ -0,0 +1,19 @@
1
+ class window.<%= plural_class_name %>SelectorView extends Backbone.View
2
+ template: JST['templates/<%= plural_file_name %>_selector']
3
+
4
+ context: =>
5
+ {}
6
+
7
+ render: =>
8
+ @available_view?.remove()
9
+ @existing_view?.remove()
10
+
11
+ @$el.html @template @context()
12
+
13
+ @available_view = new <%= plural_class_name %>SelectorListView collection: @model.available_<%= plural_file_name %>
14
+ @$('.available').html @available_view.render().$el
15
+
16
+ @existing_view = new <%= plural_class_name %>SelectorListView collection: @model.<%= plural_file_name %>
17
+ @$('.existing').html @existing_view.render().$el
18
+
19
+ this
@@ -6,3 +6,4 @@ class window.<%= class_name %>View extends Backbone.View
6
6
 
7
7
  render: =>
8
8
  @$el.html @template @context()
9
+ this
@@ -1,3 +1,3 @@
1
1
  module RailsBackboneGenerators
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_backbone_generators
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Jade Meskill
@@ -9,11 +10,12 @@ authors:
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2013-12-03 00:00:00.000000000 Z
13
+ date: 2013-12-18 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: bundler
16
17
  requirement: !ruby/object:Gem::Requirement
18
+ none: false
17
19
  requirements:
18
20
  - - ~>
19
21
  - !ruby/object:Gem::Version
@@ -21,6 +23,7 @@ dependencies:
21
23
  type: :development
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
24
27
  requirements:
25
28
  - - ~>
26
29
  - !ruby/object:Gem::Version
@@ -61,6 +64,22 @@ files:
61
64
  - lib/generators/backbone/router/router_generator.rb
62
65
  - lib/generators/backbone/router/templates/router.js.coffee
63
66
  - lib/generators/backbone/router/templates/router_spec.js.coffee
67
+ - lib/generators/backbone/selector/USAGE
68
+ - lib/generators/backbone/selector/selector_generator.rb
69
+ - lib/generators/backbone/selector/templates/collection.js.coffee
70
+ - lib/generators/backbone/selector/templates/collection_spec.js.coffee
71
+ - lib/generators/backbone/selector/templates/list.jst.eco
72
+ - lib/generators/backbone/selector/templates/list_view.js.coffee
73
+ - lib/generators/backbone/selector/templates/list_view_spec.js.coffee
74
+ - lib/generators/backbone/selector/templates/model.js.coffee
75
+ - lib/generators/backbone/selector/templates/model_spec.js.coffee
76
+ - lib/generators/backbone/selector/templates/receiver_model.js.coffee
77
+ - lib/generators/backbone/selector/templates/router.js.coffee
78
+ - lib/generators/backbone/selector/templates/row.jst.eco
79
+ - lib/generators/backbone/selector/templates/row_view.js.coffee
80
+ - lib/generators/backbone/selector/templates/row_view_spec.js.coffee
81
+ - lib/generators/backbone/selector/templates/template.jst.eco
82
+ - lib/generators/backbone/selector/templates/view.js.coffee
64
83
  - lib/generators/backbone/table_view/USAGE
65
84
  - lib/generators/backbone/table_view/table_view_generator.rb
66
85
  - lib/generators/backbone/table_view/templates/collection.js.coffee
@@ -83,26 +102,28 @@ files:
83
102
  homepage: https://github.com/integrum/rails_backbone_generators
84
103
  licenses:
85
104
  - MIT
86
- metadata: {}
87
105
  post_install_message:
88
106
  rdoc_options: []
89
107
  require_paths:
90
108
  - lib
91
109
  required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
92
111
  requirements:
93
- - - '>='
112
+ - - ! '>='
94
113
  - !ruby/object:Gem::Version
95
114
  version: '0'
96
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
97
117
  requirements:
98
- - - '>='
118
+ - - ! '>='
99
119
  - !ruby/object:Gem::Version
100
120
  version: '0'
101
121
  requirements: []
102
122
  rubyforge_project:
103
- rubygems_version: 2.0.3
123
+ rubygems_version: 1.8.23
104
124
  signing_key:
105
- specification_version: 4
125
+ specification_version: 3
106
126
  summary: Generators for creating CoffeeScript Backbone Views, Models, Collections
107
127
  and Routers
108
128
  test_files: []
129
+ has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 86266e6b41bcefae6e79d9e5164ae3d0400ae28f
4
- data.tar.gz: d8055efbdb75c5b706e1d19f8777df8367608fd9
5
- SHA512:
6
- metadata.gz: 53ff6ed2f98a621cc1a029e878582d400a2c4f12946fce2762e637eefedeb1d896fe2c81b58b14865ccbfc04cc46f9d6d7f2397938ce2fb1a581e0f0ed206bcc
7
- data.tar.gz: 11d5b2a6cd2460d7d30b6dc535dbb695bcc660e96f3ecd46cc6c67dacfc514fd7bb76b31333ef1ccd6ec8e2c41edd8c2c2f0a4190cad802d9d0204c9b531a630