couch 0.0.4 → 0.1.0
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.
- data/couch.gemspec +6 -2
- data/lib/couch/actions/base.rb +1 -11
- data/lib/couch/actions/net_base.rb +21 -0
- data/lib/couch/actions/pull.rb +2 -2
- data/lib/couch/actions/push.rb +2 -2
- data/lib/couch/actions/routes.rb +41 -0
- data/lib/couch/commands.rb +3 -0
- data/lib/couch/commands/routes.rb +4 -0
- data/lib/couch/generators/application/templates/_attachments/index.html +0 -3
- data/lib/couch/generators/list/templates/list.js +13 -7
- data/lib/couch/generators/scaffold/scaffold_generator.rb +11 -4
- data/lib/couch/generators/show/templates/show.js +8 -7
- data/lib/couch/generators/validation/templates/validate_doc_update.js +3 -0
- data/lib/couch/generators/validation/validation_generator.rb +5 -0
- data/lib/couch/generators/view/templates/map.js +1 -1
- data/lib/couch/generators/view/view_generator.rb +6 -0
- data/lib/couch/version.rb +1 -1
- metadata +7 -3
data/couch.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{couch}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.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-
|
12
|
+
s.date = %q{2010-03-09}
|
13
13
|
s.default_executable = %q{couch}
|
14
14
|
s.description = %q{With Couch you can easy build a standalone CouchDB application.}
|
15
15
|
s.email = %q{schmidt@netzmerk.com}
|
@@ -27,13 +27,16 @@ Gem::Specification.new do |s|
|
|
27
27
|
"couch.gemspec",
|
28
28
|
"lib/couch.rb",
|
29
29
|
"lib/couch/actions/base.rb",
|
30
|
+
"lib/couch/actions/net_base.rb",
|
30
31
|
"lib/couch/actions/pull.rb",
|
31
32
|
"lib/couch/actions/push.rb",
|
33
|
+
"lib/couch/actions/routes.rb",
|
32
34
|
"lib/couch/commands.rb",
|
33
35
|
"lib/couch/commands/destroy.rb",
|
34
36
|
"lib/couch/commands/generate.rb",
|
35
37
|
"lib/couch/commands/pull.rb",
|
36
38
|
"lib/couch/commands/push.rb",
|
39
|
+
"lib/couch/commands/routes.rb",
|
37
40
|
"lib/couch/generators.rb",
|
38
41
|
"lib/couch/generators/application/USAGE",
|
39
42
|
"lib/couch/generators/application/application_generator.rb",
|
@@ -55,6 +58,7 @@ Gem::Specification.new do |s|
|
|
55
58
|
"lib/couch/generators/show/show_generator.rb",
|
56
59
|
"lib/couch/generators/show/templates/show.js",
|
57
60
|
"lib/couch/generators/validation/USAGE",
|
61
|
+
"lib/couch/generators/validation/templates/validate_doc_update.js",
|
58
62
|
"lib/couch/generators/validation/validation_generator.rb",
|
59
63
|
"lib/couch/generators/view/USAGE",
|
60
64
|
"lib/couch/generators/view/templates/map.js",
|
data/lib/couch/actions/base.rb
CHANGED
@@ -1,26 +1,16 @@
|
|
1
1
|
require 'couch'
|
2
|
-
require 'couch/mapper'
|
3
2
|
|
4
3
|
require 'rubygems'
|
5
|
-
require "rest_client"
|
6
|
-
require 'json'
|
7
4
|
require 'thor/group'
|
8
|
-
require 'active_support/
|
5
|
+
require 'active_support/inflector'
|
9
6
|
|
10
7
|
module Couch
|
11
8
|
module Actions
|
12
9
|
class Base < Thor::Group
|
13
|
-
attr_reader :mapper
|
14
|
-
|
15
10
|
include Thor::Actions
|
16
11
|
|
17
12
|
class_option :database, :type => :string
|
18
13
|
|
19
|
-
def initialize(*args)
|
20
|
-
super
|
21
|
-
@mapper = Mapper.new(destination_root)
|
22
|
-
end
|
23
|
-
|
24
14
|
def self.banner
|
25
15
|
"couch #{to_s.split('::').last.underscore}"
|
26
16
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'couch'
|
2
|
+
require 'couch/mapper'
|
3
|
+
require 'couch/actions/base'
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require "rest_client"
|
7
|
+
require 'json'
|
8
|
+
|
9
|
+
module Couch
|
10
|
+
module Actions
|
11
|
+
class NetBase < Base
|
12
|
+
attr_reader :mapper
|
13
|
+
|
14
|
+
def initialize(*args)
|
15
|
+
super
|
16
|
+
@mapper = Mapper.new(destination_root)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
data/lib/couch/actions/pull.rb
CHANGED
data/lib/couch/actions/push.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'couch/actions/base'
|
2
|
+
|
3
|
+
module Couch
|
4
|
+
module Actions
|
5
|
+
class Routes < Base
|
6
|
+
def routes
|
7
|
+
say 'Static:'
|
8
|
+
Dir.glob(File.join(destination_root, "_attachments/*.html")).each do |file|
|
9
|
+
say ' %s' % attachment_url(file)
|
10
|
+
end
|
11
|
+
|
12
|
+
say 'Lists:'
|
13
|
+
Dir.glob(File.join(destination_root, "lists/*.js")).each do |list|
|
14
|
+
Dir.glob(File.join(destination_root, "views/*")).each do |view|
|
15
|
+
say ' %s' % list_url(list, view)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
say 'Shows:'
|
20
|
+
Dir.glob(File.join(destination_root, "shows/*.js")).each do |show|
|
21
|
+
say ' %s' % show_url(show)
|
22
|
+
say ' %s' % show_url(show, '/:id')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
def attachment_url(file)
|
29
|
+
File.join(database, '_design', File.basename(database), File.basename(file))
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_url(list, view)
|
33
|
+
File.join(database, '_design', File.basename(database), '_list', File.basename(view), File.basename(list, '.js'))
|
34
|
+
end
|
35
|
+
|
36
|
+
def show_url(show, id = '/')
|
37
|
+
File.join(database, '_design', File.basename(database), '_show', File.basename(show, '.js'), id)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/couch/commands.rb
CHANGED
@@ -9,6 +9,7 @@ The most common couch commands are:
|
|
9
9
|
generate Generate new code (short-cut alias: "g")
|
10
10
|
push Push application code to CouchDB
|
11
11
|
pull Pull latest application code from CouchDB
|
12
|
+
routes List application urls
|
12
13
|
|
13
14
|
In addition to those, there are:
|
14
15
|
destroy Undo code generated with "generate"
|
@@ -26,6 +27,8 @@ when 'push'
|
|
26
27
|
require 'couch/commands/push'
|
27
28
|
when 'pull'
|
28
29
|
require 'couch/commands/pull'
|
30
|
+
when 'routes'
|
31
|
+
require 'couch/commands/routes'
|
29
32
|
|
30
33
|
when '--help', '-h'
|
31
34
|
puts HELP_TEXT
|
@@ -1,18 +1,24 @@
|
|
1
1
|
function(head, req) {
|
2
2
|
provides("html", function() {
|
3
|
-
var header = '<html><head><link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8"></head><body><h1>Listing <%= pluralized_model_name.humanize %></h1
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
var header = '<html><head><link rel="stylesheet" href="../../stylesheets/application.css" type="text/css" media="screen" charset="utf-8"></head><body><h1>Listing <%= pluralized_model_name.humanize %></h1>';
|
4
|
+
|
5
|
+
header += '<p><a href="../../_show/<%= model_name %>/">New <%= model_name.humanize %></a></p>';
|
6
|
+
|
7
|
+
header += '<table><tr>';
|
8
|
+
<% attributes.each do |attribute| -%>
|
9
|
+
header += '<th><%= attribute.humanize %></th>';
|
10
|
+
<% end -%>
|
11
|
+
header += '<th></th>';
|
7
12
|
header += '</tr>';
|
8
13
|
send(header);
|
9
14
|
|
10
15
|
var row;
|
11
16
|
while (row = getRow()) {
|
12
17
|
var body = '<tr>';
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
<% attributes.each do |attribute| -%>
|
19
|
+
body += '<td>' + row.value['<%= attribute %>'] + '</td>';
|
20
|
+
<% end -%>
|
21
|
+
body += '<td><a href="../../_show/<%= model_name %>/' + row.id + '" alt="Show <%= model_name.humanize %>">Show</a></td>';
|
16
22
|
body += '</tr>';
|
17
23
|
send(body);
|
18
24
|
}
|
@@ -3,19 +3,26 @@ require 'couch/generators/named_base'
|
|
3
3
|
module Couch::Generators
|
4
4
|
class ScaffoldGenerator < NamedBase
|
5
5
|
def create_view_function
|
6
|
-
Couch::Generators.invoke :view,
|
6
|
+
Couch::Generators.invoke :view, *invokation_options
|
7
7
|
end
|
8
8
|
|
9
9
|
def inject_validations
|
10
|
-
Couch::Generators.invoke :validation,
|
10
|
+
Couch::Generators.invoke :validation, *invokation_options
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_list_function
|
14
|
-
Couch::Generators.invoke :list,
|
14
|
+
Couch::Generators.invoke :list, *invokation_options
|
15
15
|
end
|
16
16
|
|
17
17
|
def create_show_function
|
18
|
-
Couch::Generators.invoke :show,
|
18
|
+
Couch::Generators.invoke :show, *invokation_options
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
# TODO: add default options, like --help, --force etc
|
24
|
+
def invokation_options
|
25
|
+
[[name] + attributes, { :behavior => behavior }]
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -3,17 +3,18 @@ function(doc, req) {
|
|
3
3
|
var body = '';
|
4
4
|
var tail = '</body></html>';
|
5
5
|
if(doc) {
|
6
|
-
|
6
|
+
body += '<p><a href="../../_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">List <%= pluralized_model_name.humanize %></a></p>';
|
7
|
+
<% attributes.each do |attribute| -%>
|
7
8
|
if(doc['<%= attribute %>']) {
|
8
|
-
body += '<p><strong><%= attribute.humanize %></strong>: ' + doc['<%= attribute %>'] + '</p>'
|
9
|
+
body += '<p><strong><%= attribute.humanize %></strong>: ' + doc['<%= attribute %>'] + '</p>';
|
9
10
|
}
|
10
|
-
|
11
|
+
<% end -%>
|
11
12
|
return head + '<h1>Showing <%= model_name.humanize %></h1>' + body + tail;
|
12
13
|
} else {
|
13
|
-
|
14
|
-
body += '<p><label><%= attribute.humanize %></label>: <input type="text" name="<%= model_name %>[<%= attribute %>]" id="<%= model_name %>_<%= attribute %>" /></p>'
|
15
|
-
|
16
|
-
body += '<p><input type="submit"
|
14
|
+
<% attributes.each do |attribute| -%>
|
15
|
+
body += '<p><label><%= attribute.humanize %></label>: <input type="text" name="<%= model_name %>[<%= attribute %>]" id="<%= model_name %>_<%= attribute %>" /></p>';
|
16
|
+
<% end -%>
|
17
|
+
body += '<p><input type="submit" /> <a href="../../_list/<%= pluralized_model_name %>/<%= pluralized_model_name %>">Cancel</a></p>';
|
17
18
|
return head + '<h1>New <%= model_name.humanize %></h1>' + body + tail;
|
18
19
|
}
|
19
20
|
}
|
@@ -2,6 +2,11 @@ require 'couch/generators/named_base'
|
|
2
2
|
|
3
3
|
module Couch::Generators
|
4
4
|
class ValidationGenerator < NamedBase
|
5
|
+
def create_validate_doc_update
|
6
|
+
return if File.exists?(File.join(destination_root, "validate_doc_update.js"))
|
7
|
+
template "validate_doc_update.js"
|
8
|
+
end
|
9
|
+
|
5
10
|
def inject_validations
|
6
11
|
inject_into_file "validate_doc_update.js", model_validations, :after => "function (newDoc, oldDoc, userCtx) {\n"
|
7
12
|
end
|
data/lib/couch/version.rb
CHANGED
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.4
|
9
|
+
version: 0.1.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-
|
17
|
+
date: 2010-03-09 00:00:00 +01:00
|
18
18
|
default_executable: couch
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -106,13 +106,16 @@ files:
|
|
106
106
|
- couch.gemspec
|
107
107
|
- lib/couch.rb
|
108
108
|
- lib/couch/actions/base.rb
|
109
|
+
- lib/couch/actions/net_base.rb
|
109
110
|
- lib/couch/actions/pull.rb
|
110
111
|
- lib/couch/actions/push.rb
|
112
|
+
- lib/couch/actions/routes.rb
|
111
113
|
- lib/couch/commands.rb
|
112
114
|
- lib/couch/commands/destroy.rb
|
113
115
|
- lib/couch/commands/generate.rb
|
114
116
|
- lib/couch/commands/pull.rb
|
115
117
|
- lib/couch/commands/push.rb
|
118
|
+
- lib/couch/commands/routes.rb
|
116
119
|
- lib/couch/generators.rb
|
117
120
|
- lib/couch/generators/application/USAGE
|
118
121
|
- lib/couch/generators/application/application_generator.rb
|
@@ -134,6 +137,7 @@ files:
|
|
134
137
|
- lib/couch/generators/show/show_generator.rb
|
135
138
|
- lib/couch/generators/show/templates/show.js
|
136
139
|
- lib/couch/generators/validation/USAGE
|
140
|
+
- lib/couch/generators/validation/templates/validate_doc_update.js
|
137
141
|
- lib/couch/generators/validation/validation_generator.rb
|
138
142
|
- lib/couch/generators/view/USAGE
|
139
143
|
- lib/couch/generators/view/templates/map.js
|