pbw 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/generators/pbw/rules/capability/USAGE +10 -0
- data/lib/generators/pbw/rules/capability/capability_generator.rb +11 -0
- data/lib/generators/pbw/rules/capability/templates/index.erb +6 -0
- data/lib/generators/pbw/rules/capability/templates/model.coffee +14 -0
- data/lib/generators/pbw/rules/capability/templates/router.coffee +31 -0
- data/lib/generators/pbw/rules/capability/templates/templates/edit.jst +21 -0
- data/lib/generators/pbw/rules/capability/templates/templates/index.jst +17 -0
- data/lib/generators/pbw/rules/capability/templates/templates/model.jst +8 -0
- data/lib/generators/pbw/rules/capability/templates/templates/new.jst +21 -0
- data/lib/generators/pbw/rules/capability/templates/templates/show.jst +14 -0
- data/lib/generators/pbw/rules/capability/templates/views/edit_view.coffee +24 -0
- data/lib/generators/pbw/rules/capability/templates/views/index_view.coffee +20 -0
- data/lib/generators/pbw/rules/capability/templates/views/model_view.coffee +19 -0
- data/lib/generators/pbw/rules/capability/templates/views/new_view.coffee +37 -0
- data/lib/generators/pbw/rules/capability/templates/views/show_view.coffee +8 -0
- data/lib/generators/pbw/rules/command/USAGE +4 -3
- data/lib/generators/pbw/rules/command/command_generator.rb +29 -1
- data/lib/generators/pbw/rules/command/templates/command.rb +18 -0
- data/lib/generators/pbw/rules/command/templates/index.erb +6 -0
- data/lib/generators/pbw/rules/command/templates/model.coffee +13 -0
- data/lib/generators/pbw/rules/command/templates/templates/edit.jst +17 -0
- data/lib/generators/pbw/rules/command/templates/templates/index.jst +16 -0
- data/lib/generators/pbw/rules/command/templates/templates/model.jst +7 -0
- data/lib/generators/pbw/rules/command/templates/templates/new.jst +17 -0
- data/lib/generators/pbw/rules/command/templates/templates/show.jst +9 -0
- data/lib/generators/pbw/rules/command/templates/views/edit_view.coffee +24 -0
- data/lib/generators/pbw/rules/command/templates/views/index_view.coffee +20 -0
- data/lib/generators/pbw/rules/command/templates/views/model_view.coffee +19 -0
- data/lib/generators/pbw/rules/command/templates/views/new_view.coffee +37 -0
- data/lib/generators/pbw/rules/command/templates/views/show_view.coffee +8 -0
- data/lib/generators/pbw/rules/constraint/USAGE +5 -3
- data/lib/generators/pbw/rules/constraint/constraint_generator.rb +10 -2
- data/lib/generators/pbw/rules/constraint/templates/index.erb +6 -0
- data/lib/generators/pbw/rules/constraint/templates/model.coffee +14 -0
- data/lib/generators/pbw/rules/constraint/templates/router.coffee +31 -0
- data/lib/generators/pbw/rules/constraint/templates/templates/edit.jst +21 -0
- data/lib/generators/pbw/rules/constraint/templates/templates/index.jst +17 -0
- data/lib/generators/pbw/rules/constraint/templates/templates/model.jst +8 -0
- data/lib/generators/pbw/rules/constraint/templates/templates/new.jst +21 -0
- data/lib/generators/pbw/rules/constraint/templates/templates/show.jst +14 -0
- data/lib/generators/pbw/rules/constraint/templates/views/edit_view.coffee +24 -0
- data/lib/generators/pbw/rules/constraint/templates/views/index_view.coffee +20 -0
- data/lib/generators/pbw/rules/constraint/templates/views/model_view.coffee +19 -0
- data/lib/generators/pbw/rules/constraint/templates/views/new_view.coffee +37 -0
- data/lib/generators/pbw/rules/constraint/templates/views/show_view.coffee +8 -0
- data/lib/generators/pbw/rules/process/USAGE +5 -3
- data/lib/generators/pbw/rules/process/process_generator.rb +10 -2
- data/lib/generators/pbw/rules/process/templates/index.erb +6 -0
- data/lib/generators/pbw/rules/process/templates/model.coffee +14 -0
- data/lib/generators/pbw/rules/process/templates/router.coffee +31 -0
- data/lib/generators/pbw/rules/process/templates/templates/edit.jst +21 -0
- data/lib/generators/pbw/rules/process/templates/templates/index.jst +17 -0
- data/lib/generators/pbw/rules/process/templates/templates/model.jst +8 -0
- data/lib/generators/pbw/rules/process/templates/templates/new.jst +21 -0
- data/lib/generators/pbw/rules/process/templates/templates/show.jst +14 -0
- data/lib/generators/pbw/rules/process/templates/views/edit_view.coffee +24 -0
- data/lib/generators/pbw/rules/process/templates/views/index_view.coffee +20 -0
- data/lib/generators/pbw/rules/process/templates/views/model_view.coffee +19 -0
- data/lib/generators/pbw/rules/process/templates/views/new_view.coffee +37 -0
- data/lib/generators/pbw/rules/process/templates/views/show_view.coffee +8 -0
- data/lib/generators/pbw/rules/rules.rb +4 -0
- data/lib/generators/pbw/rules/trigger/USAGE +5 -3
- data/lib/generators/pbw/rules/trigger/templates/index.erb +6 -0
- data/lib/generators/pbw/rules/trigger/templates/model.coffee +14 -0
- data/lib/generators/pbw/rules/trigger/templates/router.coffee +31 -0
- data/lib/generators/pbw/rules/trigger/templates/templates/edit.jst +21 -0
- data/lib/generators/pbw/rules/trigger/templates/templates/index.jst +17 -0
- data/lib/generators/pbw/rules/trigger/templates/templates/model.jst +8 -0
- data/lib/generators/pbw/rules/trigger/templates/templates/new.jst +21 -0
- data/lib/generators/pbw/rules/trigger/templates/templates/show.jst +14 -0
- data/lib/generators/pbw/rules/trigger/templates/views/edit_view.coffee +24 -0
- data/lib/generators/pbw/rules/trigger/templates/views/index_view.coffee +20 -0
- data/lib/generators/pbw/rules/trigger/templates/views/model_view.coffee +19 -0
- data/lib/generators/pbw/rules/trigger/templates/views/new_view.coffee +37 -0
- data/lib/generators/pbw/rules/trigger/templates/views/show_view.coffee +8 -0
- data/lib/generators/pbw/rules/trigger/trigger_generator.rb +10 -2
- data/lib/pbw/version.rb +1 -1
- metadata +69 -3
- data/lib/generators/pbw/rules/ability/USAGE +0 -8
- data/lib/generators/pbw/rules/ability/ability_generator.rb +0 -3
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
ZWExNjYwMWQ4NWQxYzk1YzU4YmQxNjE5MjIyZjdkNTc0NDZlNWI2OQ==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
MDI2MjBiZWUyY2ZiMGQxODFiMDA0YWI1YjRkMTg5M2ViNTlmYjk0Mw==
|
|
7
7
|
!binary "U0hBNTEy":
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
MWE0MjUyYWE2ODRlZjI1NjA2OTA3MTE0MzIyZDNmZGM2ODA2MzBhMDRiOTZi
|
|
10
|
+
ODY4ZjBkOGUzNzZiODg2NDlkM2UzOWFhNTQ4YTAyYjFlZDE4N2NhZWU4OTY4
|
|
11
|
+
YmYwNTEwMmU4ZGFjZWY1NDQxZGY2NGM1NmYyMzM4OGYwZWQwZTY=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
MWVlYmExMTU2OWNhMDhmZmE3Njg0Mjk0YTcxZmQ1ODY1YWQyMzRmZWFjZGMz
|
|
14
|
+
NzQ1YzNlOTQ5YWM1NGVhOTM0MmIzNTRhMDNiMzQ3YzA0OWU0YWFlZjVhMGE1
|
|
15
|
+
ZmJiODY4MTdkMWQyOGQwNjk1ZDM4N2JkZDYwZmJjNTUxYzQ0MDE=
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Description:
|
|
2
|
+
Generates rails model and controller plus Backbone scaffold for your capability class inheriting from Pbw::Capability
|
|
3
|
+
|
|
4
|
+
Example:
|
|
5
|
+
rails generate pbw:rules:capability Movement surface:boolean air:boolean instant:boolean cloaked:boolean
|
|
6
|
+
|
|
7
|
+
This will create:
|
|
8
|
+
* A model inheriting from Pbw::Capability
|
|
9
|
+
* A controller with an index method for your capability plus index.html.erb template calling Backbone
|
|
10
|
+
* Backbone scaffold for your capability class
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'generators/pbw/scaffold_generator'
|
|
2
|
+
require 'generators/pbw/rules/rules'
|
|
3
|
+
|
|
4
|
+
class Pbw::Rules::CapabilityGenerator < Pbw::Generators::ScaffoldGenerator
|
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
def base_model_class
|
|
9
|
+
"Pbw::Capability"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class <%= model_namespace %> extends Backbone.Model
|
|
2
|
+
paramRoot: '<%= singular_table_name %>'
|
|
3
|
+
urlRoot: '/pbw/capabilities/<%= class_name%>'
|
|
4
|
+
|
|
5
|
+
defaults:
|
|
6
|
+
name: null
|
|
7
|
+
_type: '<%= class_name%>'
|
|
8
|
+
<% attributes.each do |attribute| -%>
|
|
9
|
+
<%= attribute.name %>: null
|
|
10
|
+
<% end -%>
|
|
11
|
+
|
|
12
|
+
class <%= collection_namespace %>Collection extends Backbone.Collection
|
|
13
|
+
model: <%= model_namespace %>
|
|
14
|
+
url: '/pbw/capabilities/<%= class_name%>'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
class <%= router_namespace %>Router extends Backbone.Router
|
|
2
|
+
initialize: (options) ->
|
|
3
|
+
@<%= plural_model_name %> = new <%= collection_namespace %>Collection()
|
|
4
|
+
@<%= plural_model_name %>.reset options.<%= plural_model_name %>
|
|
5
|
+
|
|
6
|
+
routes:
|
|
7
|
+
"" : "index"
|
|
8
|
+
"new" : "new<%= class_name %>"
|
|
9
|
+
":id/edit" : "edit"
|
|
10
|
+
":id" : "show"
|
|
11
|
+
".*" : "index"
|
|
12
|
+
|
|
13
|
+
new<%= class_name %>: ->
|
|
14
|
+
@view = new <%= "#{view_namespace}.NewView(collection: @#{plural_name})" %>
|
|
15
|
+
$("#<%= plural_name %>").html(@view.render().el)
|
|
16
|
+
|
|
17
|
+
index: ->
|
|
18
|
+
@view = new <%= "#{view_namespace}.IndexView(#{plural_name}: @#{plural_name})" %>
|
|
19
|
+
$("#<%= plural_name %>").html(@view.render().el)
|
|
20
|
+
|
|
21
|
+
show: (id) ->
|
|
22
|
+
<%= singular_name %> = @<%= plural_name %>.get(id)
|
|
23
|
+
|
|
24
|
+
@view = new <%= "#{view_namespace}.ShowView(model: #{singular_name})" %>
|
|
25
|
+
$("#<%= plural_name %>").html(@view.render().el)
|
|
26
|
+
|
|
27
|
+
edit: (id) ->
|
|
28
|
+
<%= singular_name %> = @<%= plural_name %>.get(id)
|
|
29
|
+
|
|
30
|
+
@view = new <%= "#{view_namespace}.EditView(model: #{singular_name})" %>
|
|
31
|
+
$("#<%= plural_name %>").html(@view.render().el)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<h1>Edit <%= singular_table_name %></h1>
|
|
2
|
+
|
|
3
|
+
<form id="edit-<%= singular_table_name %>" name="<%= singular_table_name %>">
|
|
4
|
+
<div class="field">
|
|
5
|
+
<label for="name">Name:</label>
|
|
6
|
+
<input type="text" name="name" id="name" value="<%%= name %>" >
|
|
7
|
+
</div>
|
|
8
|
+
<% attributes.each do |attribute| -%>
|
|
9
|
+
<div class="field">
|
|
10
|
+
<label for="<%= attribute.name %>"> <%= attribute.human_name %>:</label>
|
|
11
|
+
<input type="text" name="<%= attribute.name %>" id="<%= attribute.name %>" value="<%%= <%= attribute.name %> %>" >
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<% end -%>
|
|
15
|
+
<div class="actions">
|
|
16
|
+
<input type="submit" value="Update <%= human_name %>" />
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
</form>
|
|
20
|
+
|
|
21
|
+
<a href="#/">Back</a>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<h1>Listing <%= plural_table_name %></h1>
|
|
2
|
+
|
|
3
|
+
<table id="<%= plural_name %>-table">
|
|
4
|
+
<tr>
|
|
5
|
+
<th>Name</th>
|
|
6
|
+
<% attributes.each do |attribute| -%>
|
|
7
|
+
<th><%= attribute.human_name %></th>
|
|
8
|
+
<% end -%>
|
|
9
|
+
<th></th>
|
|
10
|
+
<th></th>
|
|
11
|
+
<th></th>
|
|
12
|
+
</tr>
|
|
13
|
+
</table>
|
|
14
|
+
|
|
15
|
+
<br/>
|
|
16
|
+
|
|
17
|
+
<a href="#/new">New <%= human_name %></a>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<td><%%= name %></td>
|
|
2
|
+
<% attributes.each do |attribute| -%>
|
|
3
|
+
<td><%%= <%= attribute.name %> %></td>
|
|
4
|
+
<% end -%>
|
|
5
|
+
|
|
6
|
+
<td><a href="#/<%%= _id %>">Show</td>
|
|
7
|
+
<td><a href="#/<%%= _id %>/edit">Edit</td>
|
|
8
|
+
<td><a href="#/<%%= _id %>/destroy" class="destroy">Destroy</a></td>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<h1>New <%= singular_table_name %></h1>
|
|
2
|
+
|
|
3
|
+
<form id="new-<%= singular_table_name %>" name="<%= singular_table_name %>">
|
|
4
|
+
<div class="field">
|
|
5
|
+
<label for="name">Name:</label>
|
|
6
|
+
<input type="text" name="name" id="name" value="<%%= name %>" >
|
|
7
|
+
</div>
|
|
8
|
+
<% attributes.each do |attribute| -%>
|
|
9
|
+
<div class="field">
|
|
10
|
+
<label for="<%= attribute.name %>"> <%= attribute.human_name %>:</label>
|
|
11
|
+
<input type="text" name="<%= attribute.name %>" id="<%= attribute.name %>" value="<%%= <%= attribute.name %> %>" >
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
<% end -%>
|
|
15
|
+
<div class="actions">
|
|
16
|
+
<input type="submit" value="Create <%= human_name %>" />
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
</form>
|
|
20
|
+
|
|
21
|
+
<a href="#/">Back</a>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.EditView extends Backbone.View
|
|
4
|
+
template: JST["<%= jst 'edit' %>"]
|
|
5
|
+
|
|
6
|
+
events:
|
|
7
|
+
"submit #edit-<%= singular_name %>": "update"
|
|
8
|
+
|
|
9
|
+
update: (e) ->
|
|
10
|
+
e.preventDefault()
|
|
11
|
+
e.stopPropagation()
|
|
12
|
+
|
|
13
|
+
@model.save(null,
|
|
14
|
+
success: (<%= singular_name %>) =>
|
|
15
|
+
@model = <%= singular_name %>
|
|
16
|
+
window.location.hash = "/#{@model.id}"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
render: ->
|
|
20
|
+
@$el.html(@template(@model.toJSON() ))
|
|
21
|
+
|
|
22
|
+
this.$("form").backboneLink(@model)
|
|
23
|
+
|
|
24
|
+
return this
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.IndexView extends Backbone.View
|
|
4
|
+
template: JST["<%= jst 'index' %>"]
|
|
5
|
+
|
|
6
|
+
initialize: () ->
|
|
7
|
+
@options.<%= plural_model_name %>.bind('reset', @addAll)
|
|
8
|
+
|
|
9
|
+
addAll: () =>
|
|
10
|
+
@options.<%= plural_model_name %>.each(@addOne)
|
|
11
|
+
|
|
12
|
+
addOne: (<%= singular_model_name %>) =>
|
|
13
|
+
view = new <%= view_namespace %>.<%= singular_name.camelize %>View({model : <%= singular_model_name %>})
|
|
14
|
+
@$("tbody").append(view.render().el)
|
|
15
|
+
|
|
16
|
+
render: =>
|
|
17
|
+
@$el.html(@template(<%= plural_model_name %>: @options.<%= plural_model_name %>.toJSON() ))
|
|
18
|
+
@addAll()
|
|
19
|
+
|
|
20
|
+
return this
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.<%= singular_name.camelize %>View extends Backbone.View
|
|
4
|
+
template: JST["<%= jst singular_name %>"]
|
|
5
|
+
|
|
6
|
+
events:
|
|
7
|
+
"click .destroy" : "destroy"
|
|
8
|
+
|
|
9
|
+
tagName: "tr"
|
|
10
|
+
|
|
11
|
+
destroy: () ->
|
|
12
|
+
@model.destroy()
|
|
13
|
+
this.remove()
|
|
14
|
+
|
|
15
|
+
return false
|
|
16
|
+
|
|
17
|
+
render: ->
|
|
18
|
+
@$el.html(@template(@model.toJSON() ))
|
|
19
|
+
return this
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.NewView extends Backbone.View
|
|
4
|
+
template: JST["<%= jst 'new' %>"]
|
|
5
|
+
|
|
6
|
+
events:
|
|
7
|
+
"submit #new-<%= singular_name %>": "save"
|
|
8
|
+
|
|
9
|
+
constructor: (options) ->
|
|
10
|
+
super(options)
|
|
11
|
+
@model = new @collection.model()
|
|
12
|
+
|
|
13
|
+
@model.bind("change:errors", () =>
|
|
14
|
+
this.render()
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
save: (e) ->
|
|
18
|
+
e.preventDefault()
|
|
19
|
+
e.stopPropagation()
|
|
20
|
+
|
|
21
|
+
@model.unset("errors")
|
|
22
|
+
|
|
23
|
+
@collection.create(@model.toJSON(),
|
|
24
|
+
success: (<%= singular_name %>) =>
|
|
25
|
+
@model = <%= singular_name %>
|
|
26
|
+
window.location.hash = "/#{@model.id}"
|
|
27
|
+
|
|
28
|
+
error: (<%= singular_name %>, jqXHR) =>
|
|
29
|
+
@model.set({errors: $.parseJSON(jqXHR.responseText)})
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
render: ->
|
|
33
|
+
@$el.html(@template(@model.toJSON() ))
|
|
34
|
+
|
|
35
|
+
this.$("form").backboneLink(@model)
|
|
36
|
+
|
|
37
|
+
return this
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Description:
|
|
2
|
-
|
|
2
|
+
Generates command class plus Backbone scaffold
|
|
3
3
|
|
|
4
4
|
Example:
|
|
5
|
-
rails generate command
|
|
5
|
+
rails generate pbw:rules:command MoveArmy area:string
|
|
6
6
|
|
|
7
7
|
This will create:
|
|
8
|
-
|
|
8
|
+
* A command class that defines the methods needed for processing commands
|
|
9
|
+
* Backbone scaffold for your command class
|
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
require 'generators/pbw/resource_helpers'
|
|
2
|
+
require 'generators/pbw/rules/rules'
|
|
3
|
+
|
|
1
4
|
class Pbw::Rules::CommandGenerator < Rails::Generators::NamedBase
|
|
2
|
-
|
|
5
|
+
include Pbw::Generators::ResourceHelpers
|
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
7
|
+
|
|
8
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
|
9
|
+
|
|
10
|
+
def create_command
|
|
11
|
+
template "command.rb", "app/models/commands/#{file_name}.rb"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create_backbone_model
|
|
15
|
+
template "model.coffee", "#{backbone_path}/models/#{file_name}.js.coffee"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def create_view_files
|
|
19
|
+
available_views.each do |view|
|
|
20
|
+
template "views/#{view}_view.coffee", File.join(backbone_path, "views", plural_name, "#{view}_view.js.coffee")
|
|
21
|
+
template "templates/#{view}.jst", File.join(backbone_path, "templates", plural_name, "#{view}.jst.ejs")
|
|
22
|
+
end
|
|
23
|
+
template "views/model_view.coffee", File.join(backbone_path, "views", plural_name, "#{singular_name}_view.js.coffee")
|
|
24
|
+
template "templates/model.jst", File.join(backbone_path, "templates", plural_name, "#{singular_name}.jst.ejs")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
protected
|
|
28
|
+
def available_views
|
|
29
|
+
%w(index show new edit)
|
|
30
|
+
end
|
|
3
31
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class Commands::<%=class_name%>
|
|
2
|
+
<% attributes.each do |attribute| -%>
|
|
3
|
+
attr_accessor :<%=attribute.name%>
|
|
4
|
+
<% end -%>
|
|
5
|
+
attr_accessor :token
|
|
6
|
+
|
|
7
|
+
def valid_token?(token)
|
|
8
|
+
# define checks to make sure token is valid for this command
|
|
9
|
+
false
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def processes
|
|
13
|
+
# specify the processes that is called by this command
|
|
14
|
+
# return either a single object inheriting from Pbw::Process or an array of them
|
|
15
|
+
# Example:
|
|
16
|
+
# Process.where(name: 'Move')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
class <%= model_namespace %> extends Backbone.Model
|
|
2
|
+
paramRoot: '<%= singular_table_name %>'
|
|
3
|
+
urlRoot: '/pbw/commands/<%= class_name%>'
|
|
4
|
+
|
|
5
|
+
defaults:
|
|
6
|
+
_type: '<%= class_name%>'
|
|
7
|
+
<% attributes.each do |attribute| -%>
|
|
8
|
+
<%= attribute.name %>: null
|
|
9
|
+
<% end -%>
|
|
10
|
+
|
|
11
|
+
class <%= collection_namespace %>Collection extends Backbone.Collection
|
|
12
|
+
model: <%= model_namespace %>
|
|
13
|
+
url: '/pbw/commands/<%= class_name%>'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<h1>Edit <%= singular_table_name %></h1>
|
|
2
|
+
|
|
3
|
+
<form id="edit-<%= singular_table_name %>" name="<%= singular_table_name %>">
|
|
4
|
+
<% attributes.each do |attribute| -%>
|
|
5
|
+
<div class="field">
|
|
6
|
+
<label for="<%= attribute.name %>"> <%= attribute.human_name %>:</label>
|
|
7
|
+
<input type="text" name="<%= attribute.name %>" id="<%= attribute.name %>" value="<%%= <%= attribute.name %> %>" >
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<% end -%>
|
|
11
|
+
<div class="actions">
|
|
12
|
+
<input type="submit" value="Update <%= human_name %>" />
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
</form>
|
|
16
|
+
|
|
17
|
+
<a href="#/">Back</a>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<h1>Listing <%= plural_table_name %></h1>
|
|
2
|
+
|
|
3
|
+
<table id="<%= plural_name %>-table">
|
|
4
|
+
<tr>
|
|
5
|
+
<% attributes.each do |attribute| -%>
|
|
6
|
+
<th><%= attribute.human_name %></th>
|
|
7
|
+
<% end -%>
|
|
8
|
+
<th></th>
|
|
9
|
+
<th></th>
|
|
10
|
+
<th></th>
|
|
11
|
+
</tr>
|
|
12
|
+
</table>
|
|
13
|
+
|
|
14
|
+
<br/>
|
|
15
|
+
|
|
16
|
+
<a href="#/new">New <%= human_name %></a>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<h1>New <%= singular_table_name %></h1>
|
|
2
|
+
|
|
3
|
+
<form id="new-<%= singular_table_name %>" name="<%= singular_table_name %>">
|
|
4
|
+
<% attributes.each do |attribute| -%>
|
|
5
|
+
<div class="field">
|
|
6
|
+
<label for="<%= attribute.name %>"> <%= attribute.human_name %>:</label>
|
|
7
|
+
<input type="text" name="<%= attribute.name %>" id="<%= attribute.name %>" value="<%%= <%= attribute.name %> %>" >
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<% end -%>
|
|
11
|
+
<div class="actions">
|
|
12
|
+
<input type="submit" value="Create <%= human_name %>" />
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
</form>
|
|
16
|
+
|
|
17
|
+
<a href="#/">Back</a>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.EditView extends Backbone.View
|
|
4
|
+
template: JST["<%= jst 'edit' %>"]
|
|
5
|
+
|
|
6
|
+
events:
|
|
7
|
+
"submit #edit-<%= singular_name %>": "update"
|
|
8
|
+
|
|
9
|
+
update: (e) ->
|
|
10
|
+
e.preventDefault()
|
|
11
|
+
e.stopPropagation()
|
|
12
|
+
|
|
13
|
+
@model.save(null,
|
|
14
|
+
success: (<%= singular_name %>) =>
|
|
15
|
+
@model = <%= singular_name %>
|
|
16
|
+
window.location.hash = "/#{@model.id}"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
render: ->
|
|
20
|
+
@$el.html(@template(@model.toJSON() ))
|
|
21
|
+
|
|
22
|
+
this.$("form").backboneLink(@model)
|
|
23
|
+
|
|
24
|
+
return this
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.IndexView extends Backbone.View
|
|
4
|
+
template: JST["<%= jst 'index' %>"]
|
|
5
|
+
|
|
6
|
+
initialize: () ->
|
|
7
|
+
@options.<%= plural_model_name %>.bind('reset', @addAll)
|
|
8
|
+
|
|
9
|
+
addAll: () =>
|
|
10
|
+
@options.<%= plural_model_name %>.each(@addOne)
|
|
11
|
+
|
|
12
|
+
addOne: (<%= singular_model_name %>) =>
|
|
13
|
+
view = new <%= view_namespace %>.<%= singular_name.camelize %>View({model : <%= singular_model_name %>})
|
|
14
|
+
@$("tbody").append(view.render().el)
|
|
15
|
+
|
|
16
|
+
render: =>
|
|
17
|
+
@$el.html(@template(<%= plural_model_name %>: @options.<%= plural_model_name %>.toJSON() ))
|
|
18
|
+
@addAll()
|
|
19
|
+
|
|
20
|
+
return this
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.<%= singular_name.camelize %>View extends Backbone.View
|
|
4
|
+
template: JST["<%= jst singular_name %>"]
|
|
5
|
+
|
|
6
|
+
events:
|
|
7
|
+
"click .destroy" : "destroy"
|
|
8
|
+
|
|
9
|
+
tagName: "tr"
|
|
10
|
+
|
|
11
|
+
destroy: () ->
|
|
12
|
+
@model.destroy()
|
|
13
|
+
this.remove()
|
|
14
|
+
|
|
15
|
+
return false
|
|
16
|
+
|
|
17
|
+
render: ->
|
|
18
|
+
@$el.html(@template(@model.toJSON() ))
|
|
19
|
+
return this
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<%= view_namespace %> ||= {}
|
|
2
|
+
|
|
3
|
+
class <%= view_namespace %>.NewView extends Backbone.View
|
|
4
|
+
template: JST["<%= jst 'new' %>"]
|
|
5
|
+
|
|
6
|
+
events:
|
|
7
|
+
"submit #new-<%= singular_name %>": "save"
|
|
8
|
+
|
|
9
|
+
constructor: (options) ->
|
|
10
|
+
super(options)
|
|
11
|
+
@model = new @collection.model()
|
|
12
|
+
|
|
13
|
+
@model.bind("change:errors", () =>
|
|
14
|
+
this.render()
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
save: (e) ->
|
|
18
|
+
e.preventDefault()
|
|
19
|
+
e.stopPropagation()
|
|
20
|
+
|
|
21
|
+
@model.unset("errors")
|
|
22
|
+
|
|
23
|
+
@collection.create(@model.toJSON(),
|
|
24
|
+
success: (<%= singular_name %>) =>
|
|
25
|
+
@model = <%= singular_name %>
|
|
26
|
+
window.location.hash = "/#{@model.id}"
|
|
27
|
+
|
|
28
|
+
error: (<%= singular_name %>, jqXHR) =>
|
|
29
|
+
@model.set({errors: $.parseJSON(jqXHR.responseText)})
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
render: ->
|
|
33
|
+
@$el.html(@template(@model.toJSON() ))
|
|
34
|
+
|
|
35
|
+
this.$("form").backboneLink(@model)
|
|
36
|
+
|
|
37
|
+
return this
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Description:
|
|
2
|
-
|
|
2
|
+
Generates rails model and controller plus Backbone scaffold for your constraint class inheriting from Pbw::Constraint
|
|
3
3
|
|
|
4
4
|
Example:
|
|
5
|
-
rails generate constraint
|
|
5
|
+
rails generate pbw:rules:constraint ItemCapacity cargo:integer life:integer
|
|
6
6
|
|
|
7
7
|
This will create:
|
|
8
|
-
|
|
8
|
+
* A model inheriting from Pbw::Constraint
|
|
9
|
+
* A controller with an index method for your constraint plus index.html.erb template calling Backbone
|
|
10
|
+
* Backbone scaffold for your constraint class
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
require 'generators/pbw/scaffold_generator'
|
|
2
|
+
require 'generators/pbw/rules/rules'
|
|
3
|
+
|
|
4
|
+
class Pbw::Rules::ConstraintGenerator < Pbw::Generators::ScaffoldGenerator
|
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
def base_model_class
|
|
9
|
+
"Pbw::Constraint"
|
|
10
|
+
end
|
|
3
11
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class <%= model_namespace %> extends Backbone.Model
|
|
2
|
+
paramRoot: '<%= singular_table_name %>'
|
|
3
|
+
urlRoot: '/pbw/constraints/<%= class_name%>'
|
|
4
|
+
|
|
5
|
+
defaults:
|
|
6
|
+
name: null
|
|
7
|
+
_type: '<%= class_name%>'
|
|
8
|
+
<% attributes.each do |attribute| -%>
|
|
9
|
+
<%= attribute.name %>: null
|
|
10
|
+
<% end -%>
|
|
11
|
+
|
|
12
|
+
class <%= collection_namespace %>Collection extends Backbone.Collection
|
|
13
|
+
model: <%= model_namespace %>
|
|
14
|
+
url: '/pbw/constraints/<%= class_name%>'
|