pbw 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/app/models/pbw/area.rb +85 -2
- data/app/models/pbw/capability.rb +28 -0
- data/app/models/pbw/changeset.rb +22 -0
- data/app/models/pbw/constraint.rb +23 -0
- data/app/models/pbw/item.rb +36 -0
- data/app/models/pbw/item_container.rb +82 -2
- data/app/models/pbw/item_conversion.rb +66 -2
- data/app/models/pbw/process.rb +41 -2
- data/app/models/pbw/rule.rb +1 -2
- data/app/models/pbw/token.rb +134 -2
- data/app/models/pbw/trigger.rb +9 -0
- data/app/models/pbw/user.rb +1 -1
- data/config/initializers/devise.rb +0 -2
- data/config/routes.rb +10 -7
- data/lib/generators/pbw/area/USAGE +5 -3
- data/lib/generators/pbw/area/area_generator.rb +5 -0
- data/lib/generators/pbw/area/templates/model.coffee +2 -2
- data/lib/generators/pbw/install/USAGE +7 -0
- data/lib/generators/pbw/item/USAGE +5 -3
- data/lib/generators/pbw/item/item_generator.rb +9 -2
- data/lib/generators/pbw/item/templates/index.erb +6 -0
- data/lib/generators/pbw/item/templates/model.coffee +14 -0
- data/lib/generators/pbw/item/templates/router.coffee +31 -0
- data/lib/generators/pbw/item/templates/templates/edit.jst +21 -0
- data/lib/generators/pbw/item/templates/templates/index.jst +17 -0
- data/lib/generators/pbw/item/templates/templates/model.jst +8 -0
- data/lib/generators/pbw/item/templates/templates/new.jst +21 -0
- data/lib/generators/pbw/item/templates/templates/show.jst +14 -0
- data/lib/generators/pbw/item/templates/views/edit_view.coffee +24 -0
- data/lib/generators/pbw/item/templates/views/index_view.coffee +20 -0
- data/lib/generators/pbw/item/templates/views/model_view.coffee +19 -0
- data/lib/generators/pbw/item/templates/views/new_view.coffee +37 -0
- data/lib/generators/pbw/item/templates/views/show_view.coffee +8 -0
- data/lib/generators/pbw/rules/command/command_generator.rb +3 -0
- data/lib/generators/pbw/scaffold_generator.rb +2 -1
- data/lib/generators/pbw/token/USAGE +5 -3
- data/lib/generators/pbw/token/templates/index.erb +6 -0
- data/lib/generators/pbw/token/templates/model.coffee +14 -0
- data/lib/generators/pbw/token/templates/router.coffee +31 -0
- data/lib/generators/pbw/token/templates/templates/edit.jst +21 -0
- data/lib/generators/pbw/token/templates/templates/index.jst +17 -0
- data/lib/generators/pbw/token/templates/templates/model.jst +8 -0
- data/lib/generators/pbw/token/templates/templates/new.jst +21 -0
- data/lib/generators/pbw/token/templates/templates/show.jst +14 -0
- data/lib/generators/pbw/token/templates/views/edit_view.coffee +24 -0
- data/lib/generators/pbw/token/templates/views/index_view.coffee +20 -0
- data/lib/generators/pbw/token/templates/views/model_view.coffee +19 -0
- data/lib/generators/pbw/token/templates/views/new_view.coffee +37 -0
- data/lib/generators/pbw/token/templates/views/show_view.coffee +8 -0
- data/lib/generators/pbw/token/token_generator.rb +8 -1
- data/lib/pbw/version.rb +1 -1
- metadata +31 -5
- data/app/models/pbw/user_token.rb +0 -16
- data/lib/generators/pbw/command/command_generator.rb +0 -3
- /data/lib/generators/pbw/{command → rules/command}/USAGE +0 -0
@@ -1,8 +1,10 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates rails model and controller plus Backbone scaffold for your area class inheriting from Pbw::Area
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate area
|
5
|
+
rails generate pbw:area Room description:string
|
6
6
|
|
7
7
|
This will create:
|
8
|
-
|
8
|
+
* A model inheriting from Pbw::Area
|
9
|
+
* A controller with an index method for your area plus index.html.erb template calling Backbone
|
10
|
+
* Backbone scaffold for your area class
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class <%= model_namespace %> extends Backbone.Model
|
2
2
|
paramRoot: '<%= singular_table_name %>'
|
3
|
-
urlRoot: '/pbw/areas
|
3
|
+
urlRoot: '/pbw/areas/<%= class_name%>'
|
4
4
|
|
5
5
|
defaults:
|
6
6
|
name: null
|
@@ -11,4 +11,4 @@ class <%= model_namespace %> extends Backbone.Model
|
|
11
11
|
|
12
12
|
class <%= collection_namespace %>Collection extends Backbone.Collection
|
13
13
|
model: <%= model_namespace %>
|
14
|
-
url: '/pbw/areas'
|
14
|
+
url: '/pbw/areas/<%= class_name%>'
|
@@ -3,3 +3,10 @@ Description:
|
|
3
3
|
|
4
4
|
Example:
|
5
5
|
rails generate pbw:install
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
* Backbone assets and directory layout in your app/assets/javascript directory
|
9
|
+
* Configuration file for mongoid in config directory
|
10
|
+
* Mount route for the pbw engine at "/pbw"
|
11
|
+
* Devise view templates in app/views/devise
|
12
|
+
* Application layout for the Pbw engine in app/views/pbw/layouts
|
@@ -1,8 +1,10 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates rails model and controller plus Backbone scaffold for your item class inheriting from Pbw::Item
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate item
|
5
|
+
rails generate pbw:item TradeGood value:float description:string
|
6
6
|
|
7
7
|
This will create:
|
8
|
-
|
8
|
+
* A model inheriting from Pbw::Item
|
9
|
+
* A controller with an index method for your area plus index.html.erb template calling Backbone
|
10
|
+
* Backbone scaffold for your item class
|
@@ -1,3 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'generators/pbw/scaffold_generator'
|
2
|
+
|
3
|
+
class Pbw::ItemGenerator < Pbw::Generators::ScaffoldGenerator
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
protected
|
7
|
+
def base_model_class
|
8
|
+
"Pbw::Item"
|
9
|
+
end
|
3
10
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class <%= model_namespace %> extends Backbone.Model
|
2
|
+
paramRoot: '<%= singular_table_name %>'
|
3
|
+
urlRoot: '/pbw/items/<%= 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/items/<%= 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
|
@@ -21,10 +21,11 @@ module Pbw
|
|
21
21
|
generate "model", "#{class_name} #{attributes.map{|attr| "#{attr.name}:#{attr.type}"}.join(' ')}"
|
22
22
|
template "index.erb", "app/views/#{plural_name}/index.html.erb"
|
23
23
|
generate "controller", "#{plural_name} index --skip"
|
24
|
-
gsub_file "app/models/#{file_name}.rb", "class #{class_name}", "class #{class_name} <
|
24
|
+
gsub_file "app/models/#{file_name}.rb", "class #{class_name}", "class #{class_name} < #{base_model_class}"
|
25
25
|
gsub_file "app/models/#{file_name}.rb", "include Mongoid::Document", ""
|
26
26
|
end
|
27
27
|
|
28
|
+
protected
|
28
29
|
def available_views
|
29
30
|
%w(index show new edit)
|
30
31
|
end
|
@@ -1,8 +1,10 @@
|
|
1
1
|
Description:
|
2
|
-
|
2
|
+
Generates rails model and controller plus Backbone scaffold for your token class inheriting from Pbw::Token
|
3
3
|
|
4
4
|
Example:
|
5
|
-
rails generate token
|
5
|
+
rails generate pbw:token Adventurer health:integer experience:integer
|
6
6
|
|
7
7
|
This will create:
|
8
|
-
|
8
|
+
* A model inheriting from Pbw::Token
|
9
|
+
* A controller with an index method for your token plus index.html.erb template calling Backbone
|
10
|
+
* Backbone scaffold for your token class
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class <%= model_namespace %> extends Backbone.Model
|
2
|
+
paramRoot: '<%= singular_table_name %>'
|
3
|
+
urlRoot: '/pbw/tokens/<%= 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/tokens/<%= 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,3 +1,10 @@
|
|
1
|
-
|
1
|
+
require 'generators/pbw/scaffold_generator'
|
2
|
+
|
3
|
+
class Pbw::TokenGenerator < Pbw::Generators::ScaffoldGenerator
|
2
4
|
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
protected
|
7
|
+
def base_model_class
|
8
|
+
"Pbw::Token"
|
9
|
+
end
|
3
10
|
end
|
data/lib/pbw/version.rb
CHANGED