jchris-couchrest 0.9.12 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.rdoc → README.md} +10 -8
- data/Rakefile +60 -39
- data/THANKS.md +18 -0
- data/examples/word_count/markov +1 -1
- data/examples/word_count/views/word_count/count-reduce.js +2 -2
- data/examples/word_count/word_count.rb +2 -2
- data/examples/word_count/word_count_query.rb +2 -2
- data/lib/couchrest/commands/push.rb +8 -4
- data/lib/couchrest/core/database.rb +95 -14
- data/lib/couchrest/core/design.rb +89 -0
- data/lib/couchrest/core/document.rb +63 -0
- data/lib/couchrest/core/model.rb +203 -120
- data/lib/couchrest/core/server.rb +1 -1
- data/lib/couchrest/core/view.rb +4 -0
- data/lib/couchrest/helper/pager.rb +10 -10
- data/lib/couchrest/monkeypatches.rb +1 -1
- data/lib/couchrest.rb +20 -2
- data/spec/couchrest/core/couchrest_spec.rb +33 -23
- data/spec/couchrest/core/database_spec.rb +163 -8
- data/spec/couchrest/core/design_spec.rb +131 -0
- data/spec/couchrest/core/document_spec.rb +130 -0
- data/spec/couchrest/core/model_spec.rb +319 -35
- data/spec/couchrest/helpers/pager_spec.rb +2 -2
- data/spec/fixtures/attachments/README +3 -0
- data/spec/spec_helper.rb +17 -3
- data/utils/remap.rb +2 -2
- data/utils/subset.rb +2 -2
- metadata +24 -33
- data/THANKS +0 -15
- data/bin/couchapp +0 -55
- data/bin/couchview +0 -48
- data/lib/couchrest/helper/file_manager.rb +0 -285
- data/lib/couchrest/helper/templates/example-map.js +0 -8
- data/lib/couchrest/helper/templates/example-reduce.js +0 -10
- data/lib/couchrest/helper/templates/index.html +0 -26
- data/spec/couchapp_spec.rb +0 -82
- data/spec/couchrest/helpers/file_manager_spec.rb +0 -170
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jchris-couchrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J. Chris Anderson
|
@@ -9,8 +9,8 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
13
|
-
default_executable:
|
12
|
+
date: 2008-11-22 00:00:00 -08:00
|
13
|
+
default_executable: couchdir
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|
@@ -30,6 +30,15 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: "0.5"
|
32
32
|
version:
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mime-types
|
35
|
+
version_requirement:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: "1.15"
|
41
|
+
version:
|
33
42
|
- !ruby/object:Gem::Dependency
|
34
43
|
name: extlib
|
35
44
|
version_requirement:
|
@@ -40,25 +49,21 @@ dependencies:
|
|
40
49
|
version: 0.9.6
|
41
50
|
version:
|
42
51
|
description: CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments.
|
43
|
-
email: jchris@
|
52
|
+
email: jchris@apache.org
|
44
53
|
executables:
|
45
|
-
- couchview
|
46
54
|
- couchdir
|
47
|
-
- couchapp
|
48
55
|
extensions: []
|
49
56
|
|
50
57
|
extra_rdoc_files:
|
51
|
-
- README.
|
58
|
+
- README.md
|
52
59
|
- LICENSE
|
53
|
-
- THANKS
|
60
|
+
- THANKS.md
|
54
61
|
files:
|
55
62
|
- LICENSE
|
56
|
-
- README.
|
63
|
+
- README.md
|
57
64
|
- Rakefile
|
58
|
-
- THANKS
|
59
|
-
- bin/couchapp
|
65
|
+
- THANKS.md
|
60
66
|
- bin/couchdir
|
61
|
-
- bin/couchview
|
62
67
|
- examples/model
|
63
68
|
- examples/model/example.rb
|
64
69
|
- examples/word_count
|
@@ -81,45 +86,31 @@ files:
|
|
81
86
|
- lib/couchrest/commands/push.rb
|
82
87
|
- lib/couchrest/core
|
83
88
|
- lib/couchrest/core/database.rb
|
89
|
+
- lib/couchrest/core/design.rb
|
90
|
+
- lib/couchrest/core/document.rb
|
84
91
|
- lib/couchrest/core/model.rb
|
85
92
|
- lib/couchrest/core/server.rb
|
93
|
+
- lib/couchrest/core/view.rb
|
86
94
|
- lib/couchrest/helper
|
87
|
-
- lib/couchrest/helper/file_manager.rb
|
88
95
|
- lib/couchrest/helper/pager.rb
|
89
96
|
- lib/couchrest/helper/streamer.rb
|
90
|
-
- lib/couchrest/helper/templates
|
91
|
-
- lib/couchrest/helper/templates/example-map.js
|
92
|
-
- lib/couchrest/helper/templates/example-reduce.js
|
93
|
-
- lib/couchrest/helper/templates/index.html
|
94
97
|
- lib/couchrest/monkeypatches.rb
|
95
98
|
- lib/couchrest.rb
|
96
|
-
- spec/couchapp_spec.rb
|
97
99
|
- spec/couchrest
|
98
100
|
- spec/couchrest/core
|
99
101
|
- spec/couchrest/core/couchrest_spec.rb
|
100
102
|
- spec/couchrest/core/database_spec.rb
|
103
|
+
- spec/couchrest/core/design_spec.rb
|
104
|
+
- spec/couchrest/core/document_spec.rb
|
101
105
|
- spec/couchrest/core/model_spec.rb
|
102
106
|
- spec/couchrest/helpers
|
103
|
-
- spec/couchrest/helpers/file_manager_spec.rb
|
104
107
|
- spec/couchrest/helpers/pager_spec.rb
|
105
108
|
- spec/couchrest/helpers/streamer_spec.rb
|
106
109
|
- spec/fixtures
|
107
110
|
- spec/fixtures/attachments
|
108
111
|
- spec/fixtures/attachments/couchdb.png
|
112
|
+
- spec/fixtures/attachments/README
|
109
113
|
- spec/fixtures/attachments/test.html
|
110
|
-
- spec/fixtures/couchapp
|
111
|
-
- spec/fixtures/couchapp/attachments
|
112
|
-
- spec/fixtures/couchapp/attachments/index.html
|
113
|
-
- spec/fixtures/couchapp/views
|
114
|
-
- spec/fixtures/couchapp/views/example-map.js
|
115
|
-
- spec/fixtures/couchapp/views/example-reduce.js
|
116
|
-
- spec/fixtures/couchapp-test
|
117
|
-
- spec/fixtures/couchapp-test/my-app
|
118
|
-
- spec/fixtures/couchapp-test/my-app/attachments
|
119
|
-
- spec/fixtures/couchapp-test/my-app/attachments/index.html
|
120
|
-
- spec/fixtures/couchapp-test/my-app/views
|
121
|
-
- spec/fixtures/couchapp-test/my-app/views/example-map.js
|
122
|
-
- spec/fixtures/couchapp-test/my-app/views/example-reduce.js
|
123
114
|
- spec/fixtures/views
|
124
115
|
- spec/fixtures/views/lib.js
|
125
116
|
- spec/fixtures/views/test_view
|
@@ -131,7 +122,7 @@ files:
|
|
131
122
|
- spec/spec_helper.rb
|
132
123
|
- utils/remap.rb
|
133
124
|
- utils/subset.rb
|
134
|
-
has_rdoc:
|
125
|
+
has_rdoc: true
|
135
126
|
homepage: http://github.com/jchris/couchrest
|
136
127
|
post_install_message:
|
137
128
|
rdoc_options: []
|
data/THANKS
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
CouchRest THANKS
|
2
|
-
=====================
|
3
|
-
|
4
|
-
CouchRest was originally developed by J. Chris Anderson <jchris@grabb.it>
|
5
|
-
and a number of other contributors. Many people further contributed to
|
6
|
-
CouchRest by reporting problems, suggesting various improvements or submitting
|
7
|
-
changes. A list of these people is included below.
|
8
|
-
|
9
|
-
* Greg Borenstein <http://ideasfordozens.com>
|
10
|
-
* Geoffrey Grosenbach <http://nubyonrails.com/>
|
11
|
-
* Simon Rozet <simon /at/ rozet /dot/ name>
|
12
|
-
|
13
|
-
Patches are welcome. The primary source for this software project is:
|
14
|
-
|
15
|
-
http://github.com/jchris/couchrest/tree/master
|
data/bin/couchapp
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../lib/couchrest'
|
5
|
-
|
6
|
-
options = {
|
7
|
-
:loud => true,
|
8
|
-
}
|
9
|
-
|
10
|
-
opts = OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage: #$0 [options] (push|pull|generate)"
|
12
|
-
opts.on('-q', '--quiet', "Omit extra debug info") do
|
13
|
-
options[:loud] = false
|
14
|
-
end
|
15
|
-
opts.on_tail('-h', '--help', "Display detailed help and exit") do
|
16
|
-
puts opts
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
opts.parse!(ARGV)
|
22
|
-
|
23
|
-
case ARGV.shift
|
24
|
-
when /generate/
|
25
|
-
appname = ARGV.shift
|
26
|
-
current = Dir.getwd
|
27
|
-
appdir = File.join(current, appname)
|
28
|
-
puts "generating couchapp in #{appdir}"
|
29
|
-
CouchRest::FileManager.generate_app(appdir)
|
30
|
-
|
31
|
-
when /push/
|
32
|
-
dirname = ARGV.shift
|
33
|
-
current = Dir.getwd
|
34
|
-
dir = File.expand_path(File.join(current, dirname))
|
35
|
-
dirapp = File.split(dir).last
|
36
|
-
if ARGV.length == 2
|
37
|
-
appname = ARGV.shift
|
38
|
-
dbstring = ARGV.shift
|
39
|
-
elsif ARGV.length == 1
|
40
|
-
appname = dirapp
|
41
|
-
dbstring = ARGV.shift
|
42
|
-
else
|
43
|
-
puts opts
|
44
|
-
puts "push dirname [appname] database"
|
45
|
-
exit(0)
|
46
|
-
end
|
47
|
-
dbspec = CouchRest.parse(dbstring)
|
48
|
-
fm = CouchRest::FileManager.new(dbspec[:database], dbspec[:host])
|
49
|
-
fm.push_app(dir, appname)
|
50
|
-
when /pull/
|
51
|
-
|
52
|
-
else
|
53
|
-
puts opts
|
54
|
-
puts "please specify a command"
|
55
|
-
end
|
data/bin/couchview
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
require 'couchrest'
|
5
|
-
|
6
|
-
%w(generate push).each do |file|
|
7
|
-
require File.dirname(__FILE__) + "/../lib/couchrest/commands/#{file}"
|
8
|
-
end
|
9
|
-
|
10
|
-
# Set defaults
|
11
|
-
options = {
|
12
|
-
:loud => true,
|
13
|
-
}
|
14
|
-
|
15
|
-
opts = OptionParser.new do |opts|
|
16
|
-
opts.banner = "Usage: #$0 [options] (push|generate) directory database"
|
17
|
-
opts.on('-q', '--quiet', "Omit extra debug info") do
|
18
|
-
options[:loud] = false
|
19
|
-
end
|
20
|
-
opts.on_tail('-h', '--help [push|generate]', "Display detailed help and exit") do |help_command|
|
21
|
-
puts opts
|
22
|
-
case help_command
|
23
|
-
when "push"
|
24
|
-
puts CouchRest::Commands::Push.help
|
25
|
-
when "generate"
|
26
|
-
puts CouchRest::Commands::Generate.help
|
27
|
-
end
|
28
|
-
exit
|
29
|
-
end
|
30
|
-
end
|
31
|
-
opts.parse!(ARGV)
|
32
|
-
|
33
|
-
options[:command] = ARGV.shift
|
34
|
-
options[:directory] = ARGV.shift
|
35
|
-
options[:trailing_args] = ARGV
|
36
|
-
|
37
|
-
# There must be a better way to check for extra required args
|
38
|
-
unless (["push", "generate"].include?(options[:command]) && options[:directory] && options[:trailing_args])
|
39
|
-
puts(opts)
|
40
|
-
exit
|
41
|
-
end
|
42
|
-
|
43
|
-
case options[:command]
|
44
|
-
when "push"
|
45
|
-
CouchRest::Commands::Push.run(options)
|
46
|
-
when "generate"
|
47
|
-
CouchRest::Commands::Generate.run(options)
|
48
|
-
end
|
@@ -1,285 +0,0 @@
|
|
1
|
-
require 'digest/md5'
|
2
|
-
|
3
|
-
module CouchRest
|
4
|
-
class FileManager
|
5
|
-
attr_reader :db
|
6
|
-
attr_accessor :loud
|
7
|
-
|
8
|
-
LANGS = {"rb" => "ruby", "js" => "javascript"}
|
9
|
-
MIMES = {
|
10
|
-
"html" => "text/html",
|
11
|
-
"htm" => "text/html",
|
12
|
-
"png" => "image/png",
|
13
|
-
"css" => "text/css",
|
14
|
-
"js" => "test/javascript"
|
15
|
-
}
|
16
|
-
def initialize(dbname, host="http://localhost:5984")
|
17
|
-
@db = CouchRest.new(host).database(dbname)
|
18
|
-
end
|
19
|
-
|
20
|
-
def push_directory(push_dir, docid=nil)
|
21
|
-
docid ||= push_dir.split('/').reverse.find{|part|!part.empty?}
|
22
|
-
|
23
|
-
pushfiles = Dir["#{push_dir}/**/*.*"].collect do |f|
|
24
|
-
{f.split("#{push_dir}/").last => open(f).read}
|
25
|
-
end
|
26
|
-
|
27
|
-
return if pushfiles.empty?
|
28
|
-
|
29
|
-
@attachments = {}
|
30
|
-
@signatures = {}
|
31
|
-
pushfiles.each do |file|
|
32
|
-
name = file.keys.first
|
33
|
-
value = file.values.first
|
34
|
-
@signatures[name] = md5(value)
|
35
|
-
|
36
|
-
@attachments[name] = {
|
37
|
-
"data" => value,
|
38
|
-
"content_type" => MIMES[name.split('.').last]
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
doc = @db.get(docid) rescue nil
|
43
|
-
|
44
|
-
unless doc
|
45
|
-
say "creating #{docid}"
|
46
|
-
@db.save({"_id" => docid, "_attachments" => @attachments, "signatures" => @signatures})
|
47
|
-
return
|
48
|
-
end
|
49
|
-
|
50
|
-
doc["signatures"] ||= {}
|
51
|
-
doc["_attachments"] ||= {}
|
52
|
-
# remove deleted docs
|
53
|
-
to_be_removed = doc["signatures"].keys.select do |d|
|
54
|
-
!pushfiles.collect{|p| p.keys.first}.include?(d)
|
55
|
-
end
|
56
|
-
|
57
|
-
to_be_removed.each do |p|
|
58
|
-
say "deleting #{p}"
|
59
|
-
doc["signatures"].delete(p)
|
60
|
-
doc["_attachments"].delete(p)
|
61
|
-
end
|
62
|
-
|
63
|
-
# update existing docs:
|
64
|
-
doc["signatures"].each do |path, sig|
|
65
|
-
if (@signatures[path] == sig)
|
66
|
-
say "no change to #{path}. skipping..."
|
67
|
-
else
|
68
|
-
say "replacing #{path}"
|
69
|
-
doc["signatures"][path] = md5(@attachments[path]["data"])
|
70
|
-
doc["_attachments"][path].delete("stub")
|
71
|
-
doc["_attachments"][path].delete("length")
|
72
|
-
doc["_attachments"][path]["data"] = @attachments[path]["data"]
|
73
|
-
doc["_attachments"][path].merge!({"data" => @attachments[path]["data"]} )
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# add in new files
|
78
|
-
new_files = pushfiles.select{|d| !doc["signatures"].keys.include?( d.keys.first) }
|
79
|
-
|
80
|
-
new_files.each do |f|
|
81
|
-
say "creating #{f}"
|
82
|
-
path = f.keys.first
|
83
|
-
content = f.values.first
|
84
|
-
doc["signatures"][path] = md5(content)
|
85
|
-
|
86
|
-
doc["_attachments"][path] = {
|
87
|
-
"data" => content,
|
88
|
-
"content_type" => MIMES[path.split('.').last]
|
89
|
-
}
|
90
|
-
end
|
91
|
-
|
92
|
-
begin
|
93
|
-
@db.save(doc)
|
94
|
-
rescue Exception => e
|
95
|
-
say e.message
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
def push_views(view_dir)
|
100
|
-
designs = {}
|
101
|
-
|
102
|
-
Dir["#{view_dir}/**/*.*"].each do |design_doc|
|
103
|
-
design_doc_parts = design_doc.split('/')
|
104
|
-
next if /^lib\..*$/.match design_doc_parts.last
|
105
|
-
pre_normalized_view_name = design_doc_parts.last.split("-")
|
106
|
-
view_name = pre_normalized_view_name[0..pre_normalized_view_name.length-2].join("-")
|
107
|
-
|
108
|
-
folder = design_doc_parts[-2]
|
109
|
-
|
110
|
-
designs[folder] ||= {}
|
111
|
-
designs[folder]["views"] ||= {}
|
112
|
-
design_lang = design_doc_parts.last.split(".").last
|
113
|
-
designs[folder]["language"] ||= LANGS[design_lang]
|
114
|
-
|
115
|
-
libs = ""
|
116
|
-
Dir["#{view_dir}/lib.#{design_lang}"].collect do |global_lib|
|
117
|
-
libs << open(global_lib).read
|
118
|
-
libs << "\n"
|
119
|
-
end
|
120
|
-
Dir["#{view_dir}/#{folder}/lib.#{design_lang}"].collect do |global_lib|
|
121
|
-
libs << open(global_lib).read
|
122
|
-
libs << "\n"
|
123
|
-
end
|
124
|
-
if design_doc_parts.last =~ /-map/
|
125
|
-
designs[folder]["views"]["#{view_name}-map"] ||= {}
|
126
|
-
|
127
|
-
designs[folder]["views"]["#{view_name}-map"]["map"] = read(design_doc, libs)
|
128
|
-
|
129
|
-
designs[folder]["views"]["#{view_name}-reduce"] ||= {}
|
130
|
-
designs[folder]["views"]["#{view_name}-reduce"]["map"] = read(design_doc, libs)
|
131
|
-
end
|
132
|
-
|
133
|
-
if design_doc_parts.last =~ /-reduce/
|
134
|
-
designs[folder]["views"]["#{view_name}-reduce"] ||= {}
|
135
|
-
|
136
|
-
designs[folder]["views"]["#{view_name}-reduce"]["reduce"] = read(design_doc, libs)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# cleanup empty maps and reduces
|
141
|
-
designs.each do |name, props|
|
142
|
-
props["views"].each do |view, funcs|
|
143
|
-
next unless view.include?("reduce")
|
144
|
-
props["views"].delete(view) unless funcs.keys.include?("reduce")
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
designs.each do |k,v|
|
149
|
-
create_or_update("_design/#{k}", v)
|
150
|
-
end
|
151
|
-
|
152
|
-
designs
|
153
|
-
end
|
154
|
-
|
155
|
-
def pull_views(view_dir)
|
156
|
-
prefix = "_design"
|
157
|
-
ds = db.documents(:startkey => '#{prefix}/', :endkey => '#{prefix}/ZZZZZZZZZ')
|
158
|
-
ds['rows'].collect{|r|r['id']}.each do |id|
|
159
|
-
puts directory = id.split('/').last
|
160
|
-
FileUtils.mkdir_p(File.join(view_dir,directory))
|
161
|
-
views = db.get(id)['views']
|
162
|
-
|
163
|
-
vgroups = views.keys.group_by{|k|k.sub(/\-(map|reduce)$/,'')}
|
164
|
-
vgroups.each do|g,vs|
|
165
|
-
mapname = vs.find {|v|views[v]["map"]}
|
166
|
-
if mapname
|
167
|
-
# save map
|
168
|
-
mapfunc = views[mapname]["map"]
|
169
|
-
mapfile = File.join(view_dir, directory, "#{g}-map.js") # todo support non-js views
|
170
|
-
File.open(mapfile,'w') do |f|
|
171
|
-
f.write mapfunc
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
reducename = vs.find {|v|views[v]["reduce"]}
|
176
|
-
if reducename
|
177
|
-
# save reduce
|
178
|
-
reducefunc = views[reducename]["reduce"]
|
179
|
-
reducefile = File.join(view_dir, directory, "#{g}-reduce.js") # todo support non-js views
|
180
|
-
File.open(reducefile,'w') do |f|
|
181
|
-
f.write reducefunc
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
end
|
188
|
-
|
189
|
-
def push_app(appdir, appname)
|
190
|
-
libs = []
|
191
|
-
viewdir = File.join(appdir,"views")
|
192
|
-
attachdir = File.join(appdir,"attachments")
|
193
|
-
views, lang = read_design_views(viewdir)
|
194
|
-
# attachments = read_attachments(attachdir)
|
195
|
-
docid = "_design/#{appname}"
|
196
|
-
design = @db.get(docid) rescue {}
|
197
|
-
design['_id'] = docid
|
198
|
-
design['views'] = views
|
199
|
-
design['language'] = lang
|
200
|
-
@db.save(design)
|
201
|
-
push_directory(attachdir, docid)
|
202
|
-
# puts views.inspect
|
203
|
-
end
|
204
|
-
|
205
|
-
# Generate an application in the given directory.
|
206
|
-
# This is a class method because it doesn't depend on
|
207
|
-
# specifying a database.
|
208
|
-
def self.generate_app(app_dir)
|
209
|
-
FileUtils.mkdir_p(app_dir)
|
210
|
-
FileUtils.mkdir_p(File.join(app_dir,"attachments"))
|
211
|
-
FileUtils.mkdir_p(File.join(app_dir,"views"))
|
212
|
-
|
213
|
-
index_template = File.join(File.expand_path(File.dirname(__FILE__)), 'templates','index.html')
|
214
|
-
index_dest = File.join(app_dir,"attachments","index.html")
|
215
|
-
FileUtils.cp(index_template, index_dest)
|
216
|
-
|
217
|
-
map_template = File.join(File.expand_path(File.dirname(__FILE__)), 'templates','example-map.js')
|
218
|
-
map_dest = File.join(app_dir,"views","example-map.js")
|
219
|
-
FileUtils.cp(map_template, map_dest)
|
220
|
-
|
221
|
-
rereduce_template = File.join(File.expand_path(File.dirname(__FILE__)), 'templates','example-reduce.js')
|
222
|
-
rereduce_dest = File.join(app_dir,"views","example-reduce.js")
|
223
|
-
FileUtils.cp(rereduce_template, rereduce_dest)
|
224
|
-
end
|
225
|
-
|
226
|
-
private
|
227
|
-
|
228
|
-
def read_design_views(viewdir)
|
229
|
-
libs = []
|
230
|
-
language = nil
|
231
|
-
views = {}
|
232
|
-
Dir["#{viewdir}/*.*"].each do |viewfile|
|
233
|
-
view_parts = viewfile.split('/')
|
234
|
-
viewfile_name = view_parts.last
|
235
|
-
# example-map.js
|
236
|
-
viewfile_name_parts = viewfile_name.split('.')
|
237
|
-
viewfile_ext = viewfile_name_parts.last
|
238
|
-
view_name_parts = viewfile_name_parts.first.split('-')
|
239
|
-
func_type = view_name_parts.pop
|
240
|
-
view_name = view_name_parts.join('-')
|
241
|
-
contents = File.open(viewfile).read
|
242
|
-
if /^lib\..*$/.match viewfile_name
|
243
|
-
libs.push(contents)
|
244
|
-
else
|
245
|
-
views[view_name] ||= {}
|
246
|
-
language = LANGS[viewfile_ext]
|
247
|
-
views[view_name][func_type] = contents.sub(/(\/\/|#)include-lib/,libs.join("\n"))
|
248
|
-
end
|
249
|
-
end
|
250
|
-
[views, language]
|
251
|
-
end
|
252
|
-
|
253
|
-
def say words
|
254
|
-
puts words if @loud
|
255
|
-
end
|
256
|
-
|
257
|
-
def md5 string
|
258
|
-
Digest::MD5.hexdigest(string)
|
259
|
-
end
|
260
|
-
|
261
|
-
def read(file, libs=nil)
|
262
|
-
st = open(file).read
|
263
|
-
st.sub!(/(\/\/|#)include-lib/,libs) if libs
|
264
|
-
st
|
265
|
-
end
|
266
|
-
|
267
|
-
def create_or_update(id, fields)
|
268
|
-
existing = @db.get(id) rescue nil
|
269
|
-
|
270
|
-
if existing
|
271
|
-
updated = existing.merge(fields)
|
272
|
-
if existing != updated
|
273
|
-
say "replacing #{id}"
|
274
|
-
db.save(updated)
|
275
|
-
else
|
276
|
-
say "skipping #{id}"
|
277
|
-
end
|
278
|
-
else
|
279
|
-
say "creating #{id}"
|
280
|
-
db.save(fields.merge({"_id" => id}))
|
281
|
-
end
|
282
|
-
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html>
|
3
|
-
<head>
|
4
|
-
<title>Generated CouchApp</title>
|
5
|
-
<link rel="stylesheet" href="screen.css" type="text/css">
|
6
|
-
</head>
|
7
|
-
<body>
|
8
|
-
<h1>Generated CouchApp</h1>
|
9
|
-
<ul id="view"></ul>
|
10
|
-
</body>
|
11
|
-
<script src="/_utils/script/json2.js"></script>
|
12
|
-
<script src="/_utils/script/jquery.js?1.2.6"></script>
|
13
|
-
<script src="/_utils/script/jquery.couch.js?0.8.0"></script>
|
14
|
-
<script type="text/javascript" charset="utf-8">
|
15
|
-
$(function() {
|
16
|
-
var dbname = document.location.href.split('/')[3];
|
17
|
-
var design = unescape(document.location.href.split('/')[4]).split('/')[1];
|
18
|
-
var DB = $.couch.db(dbname);
|
19
|
-
DB.view(design+"/example",{success: function(json) {
|
20
|
-
$("#view").html(json.rows.map(function(row) {
|
21
|
-
return '<li>'+row.key+'</li>';
|
22
|
-
}).join(''));
|
23
|
-
}});
|
24
|
-
});
|
25
|
-
</script>
|
26
|
-
</html>
|
data/spec/couchapp_spec.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
-
|
3
|
-
describe "couchapp" do
|
4
|
-
before(:all) do
|
5
|
-
@fixdir = FIXTURE_PATH + '/couchapp-test'
|
6
|
-
@couchapp = File.expand_path(File.dirname(__FILE__)) + '/../bin/couchapp'
|
7
|
-
`rm -rf #{@fixdir}`
|
8
|
-
`mkdir -p #{@fixdir}`
|
9
|
-
@run = "cd #{@fixdir} && #{@couchapp}"
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
describe "--help" do
|
14
|
-
it "should output the opts" do
|
15
|
-
`#{@run} --help`.should match(/Usage/)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "generate my-app" do
|
20
|
-
it "should create an app directory" do
|
21
|
-
`#{@run} generate my-app`.should match(/generating/i)
|
22
|
-
Dir["#{@fixdir}/*"].select{|x|x =~ /my-app/}.length.should == 1
|
23
|
-
end
|
24
|
-
it "should create a views directory" do
|
25
|
-
`#{@run} generate my-app`.should match(/generating/i)
|
26
|
-
Dir["#{@fixdir}/my-app/*"].select{|x|x =~ /views/}.length.should == 1
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "push my-app #{TESTDB}" do
|
31
|
-
before(:all) do
|
32
|
-
@cr = CouchRest.new(COUCHHOST)
|
33
|
-
@db = @cr.database(TESTDB)
|
34
|
-
@db.delete! rescue nil
|
35
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
36
|
-
`#{@run} generate my-app`
|
37
|
-
end
|
38
|
-
it "should create the design document with the app name" do
|
39
|
-
`#{@run} push my-app #{TESTDB}`
|
40
|
-
lambda{@db.get("_design/my-app")}.should_not raise_error
|
41
|
-
end
|
42
|
-
it "should create the views" do
|
43
|
-
`#{@run} push my-app #{TESTDB}`
|
44
|
-
doc = @db.get("_design/my-app")
|
45
|
-
doc['views']['example']['map'].should match(/function/)
|
46
|
-
end
|
47
|
-
it "should create the index" do
|
48
|
-
`#{@run} push my-app #{TESTDB}`
|
49
|
-
doc = @db.get("_design/my-app")
|
50
|
-
doc['_attachments']['index.html']["content_type"].should == 'text/html'
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe "push . #{TESTDB}" do
|
55
|
-
before(:all) do
|
56
|
-
@cr = CouchRest.new(COUCHHOST)
|
57
|
-
@db = @cr.database(TESTDB)
|
58
|
-
@db.delete! rescue nil
|
59
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
60
|
-
`#{@run} generate my-app`
|
61
|
-
end
|
62
|
-
it "should create the design document" do
|
63
|
-
`cd #{@fixdir}/my-app && #{@couchapp} push . #{TESTDB}`
|
64
|
-
lambda{@db.get("_design/my-app")}.should_not raise_error
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe "push my-app my-design #{TESTDB}" do
|
69
|
-
before(:all) do
|
70
|
-
@cr = CouchRest.new(COUCHHOST)
|
71
|
-
@db = @cr.database(TESTDB)
|
72
|
-
@db.delete! rescue nil
|
73
|
-
@db = @cr.create_db(TESTDB) rescue nil
|
74
|
-
`#{@run} generate my-app`
|
75
|
-
end
|
76
|
-
it "should create the design document" do
|
77
|
-
`#{@run} push my-app my-design #{TESTDB}`
|
78
|
-
lambda{@db.get("_design/my-design")}.should_not raise_error
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|