rid 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,6 +8,7 @@
8
8
  <body>
9
9
  <h1><%= app_title %></h1>
10
10
  <h2>{{title}}</h2>
11
+ <p class="notice">{{notice}}</p>
11
12
  {{>body}}
12
13
  </body>
13
14
  </html>
@@ -6,6 +6,8 @@
6
6
  <th><%= attribute.humanize %></th>
7
7
  <% end -%>
8
8
  <th></th>
9
+ <th></th>
10
+ <th></th>
9
11
  </tr>
10
12
  {{#rows}}
11
13
  <tr>
@@ -13,7 +15,9 @@
13
15
  <% attributes.each do |attribute| -%>
14
16
  <td>{{<%= attribute %>}}</td>
15
17
  <% end -%>
16
- <td><a href="{{path}}/_show/<%= model_name %>/{{id}}">Show <%= model_name.humanize %></a></td>
18
+ <td><a href="{{path}}/_show/<%= model_name %>/{{id}}">Show</a></td>
19
+ <td><a href="{{path}}/_show/<%= model_name %>/{{id}}?edit">Edit</a></td>
20
+ <td><a href="{{path}}/_show/<%= model_name %>/{{id}}?delete">Delete</a></td>
17
21
  </tr>
18
22
  {{/rows}}
19
23
  </table>
@@ -6,6 +6,8 @@ module Rid::Generators
6
6
  template "show.js", "shows/#{model_name}.js"
7
7
  template "show.mustache", "lib/templates/#{pluralized_model_name}/show.mustache"
8
8
  template "form.mustache", "lib/templates/#{pluralized_model_name}/form.mustache"
9
+ template "delete.mustache", "lib/templates/#{pluralized_model_name}/delete.mustache"
10
+ template "deleted.mustache", "lib/templates/#{pluralized_model_name}/deleted.mustache"
9
11
  end
10
12
  end
11
13
  end
@@ -0,0 +1,20 @@
1
+ <p>
2
+ <a href="{{path}}/_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a> |
3
+ <a href="{{path}}/_show/<%= model_name %>/{{id}}">Show <%= model_name.humanize %></a> |
4
+ <a href="{{path}}/_show/<%= model_name %>/{{id}}?edit">Edit <%= model_name.humanize %></a>
5
+ </p>
6
+ <h3>Are you sure you want to delete that <%= model_name.humanize %>?</h3>
7
+ <dl>
8
+ <dt>ID</dt>
9
+ <dd>{{id}}</dd>
10
+ <% attributes.each do |attribute| -%>
11
+ <dt><%= attribute.humanize %></dt>
12
+ <dd>{{<%= attribute %>}}</dd>
13
+ <% end -%>
14
+ </dl>
15
+ <form action="{{path}}/_update/<%= pluralized_model_name %>" method="post" accept-charset="utf-8">
16
+ <input type="hidden" name="rev" value="{{rev}}" id="rev" />
17
+ <input type="hidden" name="id" value="{{id}}" id="id" />
18
+ <input type="hidden" name="delete" value="true" id="delete" />
19
+ <p><input type="submit" value="Yes, delete <%= model_name.humanize %>"></p>
20
+ </form>
@@ -0,0 +1,3 @@
1
+ <p>
2
+ <a href="{{path}}/_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">Back to the list of <%= pluralized_model_name.humanize %></a>
3
+ </p>
@@ -1,5 +1,13 @@
1
- <p><a href="{{path}}/_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a></p>
1
+ <p>
2
+ <a href="{{path}}/_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a>
3
+ {{#rev}}
4
+ | <a href="{{path}}/_show/<%= model_name %>/{{id}}">Show <%= model_name.humanize %></a>
5
+ {{/rev}}
6
+ </p>
2
7
  <form action="{{path}}/_update/<%= pluralized_model_name %>" method="post" accept-charset="utf-8">
8
+ {{#rev}}
9
+ <input type="hidden" name="rev" value="{{rev}}" id="rev" />
10
+ {{/rev}}
3
11
  <p>
4
12
  <label for="id">ID</label><br/>
5
13
  <input type="text" name="id" value="{{id}}" id="id" />
@@ -10,5 +18,5 @@
10
18
  <input type="text" name="<%= attribute %>" value="{{<%= attribute %>}}" id="<%= attribute %>" />
11
19
  </p>
12
20
  <% end -%>
13
- <p><input type="submit" value="Create <%= model_name.humanize %>"></p>
21
+ <p><input type="submit" value="Save <%= model_name.humanize %>"></p>
14
22
  </form>
@@ -4,36 +4,45 @@ function(doc, req) {
4
4
  // !json templates/layout.mustache
5
5
  // !json templates/<%= pluralized_model_name %>/show.mustache
6
6
  // !json templates/<%= pluralized_model_name %>/form.mustache
7
+ // !json templates/<%= pluralized_model_name %>/delete.mustache
7
8
 
8
- if(doc) {
9
- provides("html", function() {
10
- var view = {
11
- path: path(),
12
- title: "Showing <%= model_name.humanize %>",
13
- body: {
14
- path: path(),
15
- <% attributes.each do |attribute| -%>
16
- '<%= attribute %>': doc['<%= attribute %>'],
17
- <% end -%>
18
- id: doc._id
19
- }
20
- };
21
-
22
- return Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.show });
23
- });
24
- } else {
9
+ provides("html", function() {
25
10
  var view = {
26
11
  path: path(),
27
- title: "New <%= model_name.humanize %>",
28
12
  body: {
29
- path: path(),
13
+ path: path()
14
+ }
15
+ };
16
+ var partial;
17
+
18
+ if(doc) {
30
19
  <% attributes.each do |attribute| -%>
31
- '<%= attribute %>': '',
20
+ view.body['<%= attribute %>'] = doc['<%= attribute %>'];
32
21
  <% end -%>
33
- id: ''
22
+ view.body.id = doc._id;
23
+
24
+ if (req.query.edit != undefined) {
25
+ // edit
26
+ view.title = "Editing <%= model_name.humanize %>";
27
+ partial = "form";
28
+ } else {
29
+ view.body.rev = doc._rev;
30
+ if (req.query['delete'] != undefined) {
31
+ // delete
32
+ view.title = "Deleting <%= model_name.humanize %>";
33
+ partial = "delete";
34
+ } else {
35
+ // show
36
+ view.title = "Showing <%= model_name.humanize %>";
37
+ partial = "show";
38
+ }
34
39
  }
35
- };
40
+ } else {
41
+ // new
42
+ view.title = "New <%= model_name.humanize %>";
43
+ partial = "form";
44
+ }
36
45
 
37
- return Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.form });
38
- }
46
+ return Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>[partial] });
47
+ });
39
48
  }
@@ -1,4 +1,8 @@
1
- <p><a href="{{path}}/_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a></p>
1
+ <p>
2
+ <a href="{{path}}/_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a> |
3
+ <a href="{{path}}/_show/<%= model_name %>/{{id}}?edit">Edit <%= model_name.humanize %></a> |
4
+ <a href="{{path}}/_show/<%= model_name %>/{{id}}?delete">Delete <%= model_name.humanize %></a>
5
+ </p>
2
6
  <dl>
3
7
  <dt>ID</dt>
4
8
  <dd>{{id}}</dd>
@@ -3,27 +3,46 @@ function(doc, req) {
3
3
  // !code mustache.js
4
4
  // !json templates/layout.mustache
5
5
  // !json templates/<%= pluralized_model_name %>/show.mustache
6
+ // !json templates/<%= pluralized_model_name %>/deleted.mustache
6
7
 
7
- if (!doc) {
8
- var doc = {
9
- _id: req.form.id,
10
- type: '<%= model_name %>',
8
+ var doc = {
9
+ type: '<%= model_name %>',
11
10
  <% attributes.each do |attribute| -%>
12
- '<%= attribute %>': req.form['<%= attribute %>'],
11
+ '<%= attribute %>': req.form['<%= attribute %>'],
13
12
  <% end -%>
14
- };
15
- var view = {
13
+ _id: req.form.id,
14
+ _rev: req.form.rev
15
+ };
16
+
17
+ if (req.form['delete'] == 'true') {
18
+ doc._deleted = true;
19
+ };
20
+
21
+ var view = {
22
+ path: path(),
23
+ body: {
16
24
  path: path(),
17
- title: "Created Post",
18
- body: {
19
- path: path(),
20
25
  <% attributes.each do |attribute| -%>
21
- '<%= attribute %>': doc['<%= attribute %>'],
26
+ '<%= attribute %>': doc['<%= attribute %>'],
22
27
  <% end -%>
23
- id: doc._id
24
- }
25
- };
28
+ id: doc._id
29
+ }
30
+ };
31
+ var partial;
26
32
 
27
- return [doc, Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>.show })];
33
+ if (doc._deleted) {
34
+ view.title = "Deleted <%= model_name.humanize %>";
35
+ view.notice = "<%= model_name.humanize %> has been deleted.";
36
+ partial = 'deleted';
37
+ } else {
38
+ view.title = "Showing <%= model_name.humanize %>";
39
+ if (doc._rev) {
40
+ view.notice = "<%= model_name.humanize %> has been updated.";
41
+ } else {
42
+ view.notice = "<%= model_name.humanize %> has been created.";
43
+ };
44
+ partial = 'show';
28
45
  }
46
+
47
+ return [doc, Mustache.to_html(templates.layout, view, { body: templates.<%= pluralized_model_name %>[partial] })];
29
48
  }
data/lib/rid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rid
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/rid.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rid}
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Johannes J. Schmidt"]
12
- s.date = %q{2010-03-14}
12
+ s.date = %q{2010-03-15}
13
13
  s.default_executable = %q{rid}
14
14
  s.description = %q{With Couch you can easy build a standalone CouchDB application. Couch aims to bring some of the Rails beauty to CouchDB. Currently Couch supports Rails style Generators you will love, using the same awesome Thor library used in Rails3.}
15
15
  s.email = %q{schmidt@netzmerk.com}
@@ -62,6 +62,8 @@ Gem::Specification.new do |s|
62
62
  "lib/rid/generators/scaffold/scaffold_generator.rb",
63
63
  "lib/rid/generators/show/USAGE",
64
64
  "lib/rid/generators/show/show_generator.rb",
65
+ "lib/rid/generators/show/templates/delete.mustache",
66
+ "lib/rid/generators/show/templates/deleted.mustache",
65
67
  "lib/rid/generators/show/templates/form.mustache",
66
68
  "lib/rid/generators/show/templates/show.js",
67
69
  "lib/rid/generators/show/templates/show.mustache",
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
- - 1
9
- version: 0.4.1
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Johannes J. Schmidt
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-03-14 00:00:00 +01:00
17
+ date: 2010-03-15 00:00:00 +01:00
18
18
  default_executable: rid
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -141,6 +141,8 @@ files:
141
141
  - lib/rid/generators/scaffold/scaffold_generator.rb
142
142
  - lib/rid/generators/show/USAGE
143
143
  - lib/rid/generators/show/show_generator.rb
144
+ - lib/rid/generators/show/templates/delete.mustache
145
+ - lib/rid/generators/show/templates/deleted.mustache
144
146
  - lib/rid/generators/show/templates/form.mustache
145
147
  - lib/rid/generators/show/templates/show.js
146
148
  - lib/rid/generators/show/templates/show.mustache