pbw 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -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,10 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates rails model and controller plus Backbone scaffold for your process class inheriting from Pbw::Process
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate process
|
5
|
+
rails generate pbw:rules:process Travel
|
6
6
|
|
7
7
|
This will create:
|
8
|
-
|
8
|
+
* A model inheriting from Pbw::Process
|
9
|
+
* A controller with an index method for your process plus index.html.erb template calling Backbone
|
10
|
+
* Backbone scaffold for your process class
|
@@ -1,3 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'generators/pbw/scaffold_generator'
|
2
|
+
require 'generators/pbw/rules/rules'
|
3
|
+
|
4
|
+
class Pbw::Rules::ProcessGenerator < Pbw::Generators::ScaffoldGenerator
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
6
|
+
|
7
|
+
protected
|
8
|
+
def base_model_class
|
9
|
+
"Pbw::Process"
|
10
|
+
end
|
3
11
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class <%= model_namespace %> extends Backbone.Model
|
2
|
+
paramRoot: '<%= singular_table_name %>'
|
3
|
+
urlRoot: '/pbw/processes/<%= 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/processes/<%= 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,10 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates rails model and controller plus Backbone scaffold for your trigger class inheriting from Pbw::Trigger
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate trigger
|
5
|
+
rails generate pbw:rules:trigger BattleTrigger
|
6
6
|
|
7
7
|
This will create:
|
8
|
-
|
8
|
+
* A model inheriting from Pbw::Trigger
|
9
|
+
* A controller with an index method for your trigger plus index.html.erb template calling Backbone
|
10
|
+
* Backbone scaffold for your trigger class
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class <%= model_namespace %> extends Backbone.Model
|
2
|
+
paramRoot: '<%= singular_table_name %>'
|
3
|
+
urlRoot: '/pbw/triggers/<%= 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/triggers/<%= 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>
|