couch 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitmodules +3 -0
- data/Rakefile +1 -1
- data/bin/couch +1 -0
- data/couch.gemspec +5 -15
- data/lib/couch.rb +4 -2
- data/lib/couch/actions/base.rb +0 -15
- data/lib/couch/actions/pull.rb +13 -34
- data/lib/couch/actions/push.rb +10 -9
- data/lib/couch/actions/routes.rb +3 -3
- data/lib/couch/design_document.rb +228 -0
- data/lib/couch/generators/application/application_generator.rb +13 -6
- data/lib/couch/generators/base.rb +0 -6
- data/lib/couch/generators/named_base.rb +0 -1
- data/lib/couch/version.rb +1 -1
- metadata +7 -25
- data/lib/couch/actions/net_base.rb +0 -21
- data/lib/couch/mapper.rb +0 -64
- data/spec/couch_spec.rb +0 -7
- data/spec/spec.opts +0 -1
- data/spec/spec_helper.rb +0 -9
data/.gitmodules
ADDED
data/Rakefile
CHANGED
@@ -17,7 +17,7 @@ begin
|
|
17
17
|
gem.add_dependency "rest-client", ">= 1.4.1"
|
18
18
|
gem.add_dependency "json_pure", ">= 1.2.2"
|
19
19
|
gem.add_dependency "activesupport", ">= 3.0.0.beta"
|
20
|
-
gem.add_development_dependency "rspec", ">= 1.2.9"
|
20
|
+
# gem.add_development_dependency "rspec", ">= 1.2.9"
|
21
21
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
22
22
|
end
|
23
23
|
Jeweler::GemcutterTasks.new
|
data/bin/couch
CHANGED
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.1.
|
8
|
+
s.version = "0.1.1"
|
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-10}
|
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}
|
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
".gitignore",
|
23
|
+
".gitmodules",
|
23
24
|
"LICENSE",
|
24
25
|
"README.rdoc",
|
25
26
|
"Rakefile",
|
@@ -27,7 +28,6 @@ Gem::Specification.new do |s|
|
|
27
28
|
"couch.gemspec",
|
28
29
|
"lib/couch.rb",
|
29
30
|
"lib/couch/actions/base.rb",
|
30
|
-
"lib/couch/actions/net_base.rb",
|
31
31
|
"lib/couch/actions/pull.rb",
|
32
32
|
"lib/couch/actions/push.rb",
|
33
33
|
"lib/couch/actions/routes.rb",
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/couch/commands/pull.rb",
|
38
38
|
"lib/couch/commands/push.rb",
|
39
39
|
"lib/couch/commands/routes.rb",
|
40
|
+
"lib/couch/design_document.rb",
|
40
41
|
"lib/couch/generators.rb",
|
41
42
|
"lib/couch/generators/application/USAGE",
|
42
43
|
"lib/couch/generators/application/application_generator.rb",
|
@@ -63,11 +64,7 @@ Gem::Specification.new do |s|
|
|
63
64
|
"lib/couch/generators/view/USAGE",
|
64
65
|
"lib/couch/generators/view/templates/map.js",
|
65
66
|
"lib/couch/generators/view/view_generator.rb",
|
66
|
-
"lib/couch/
|
67
|
-
"lib/couch/version.rb",
|
68
|
-
"spec/couch_spec.rb",
|
69
|
-
"spec/spec.opts",
|
70
|
-
"spec/spec_helper.rb"
|
67
|
+
"lib/couch/version.rb"
|
71
68
|
]
|
72
69
|
s.homepage = %q{http://github.com/jo/couch}
|
73
70
|
s.rdoc_options = ["--charset=UTF-8"]
|
@@ -75,10 +72,6 @@ Gem::Specification.new do |s|
|
|
75
72
|
s.rubyforge_project = %q{couch}
|
76
73
|
s.rubygems_version = %q{1.3.6}
|
77
74
|
s.summary = %q{Standalone CouchDB Application Development Suite}
|
78
|
-
s.test_files = [
|
79
|
-
"spec/spec_helper.rb",
|
80
|
-
"spec/couch_spec.rb"
|
81
|
-
]
|
82
75
|
|
83
76
|
if s.respond_to? :specification_version then
|
84
77
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -89,20 +82,17 @@ Gem::Specification.new do |s|
|
|
89
82
|
s.add_runtime_dependency(%q<rest-client>, [">= 1.4.1"])
|
90
83
|
s.add_runtime_dependency(%q<json_pure>, [">= 1.2.2"])
|
91
84
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta"])
|
92
|
-
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
93
85
|
else
|
94
86
|
s.add_dependency(%q<thor>, [">= 0.13.4"])
|
95
87
|
s.add_dependency(%q<rest-client>, [">= 1.4.1"])
|
96
88
|
s.add_dependency(%q<json_pure>, [">= 1.2.2"])
|
97
89
|
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
|
98
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
99
90
|
end
|
100
91
|
else
|
101
92
|
s.add_dependency(%q<thor>, [">= 0.13.4"])
|
102
93
|
s.add_dependency(%q<rest-client>, [">= 1.4.1"])
|
103
94
|
s.add_dependency(%q<json_pure>, [">= 1.2.2"])
|
104
95
|
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta"])
|
105
|
-
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
106
96
|
end
|
107
97
|
end
|
108
98
|
|
data/lib/couch.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
require 'rubygems'
|
1
2
|
require 'yaml'
|
3
|
+
require 'json'
|
2
4
|
|
3
5
|
module Couch
|
4
6
|
CONFIG_FILENAME = ".couchrc"
|
@@ -15,12 +17,12 @@ module Couch
|
|
15
17
|
@config ||= YAML.load(File.open config_file)
|
16
18
|
end
|
17
19
|
|
20
|
+
private
|
21
|
+
|
18
22
|
def self.config_file
|
19
23
|
File.join root, CONFIG_FILENAME
|
20
24
|
end
|
21
25
|
|
22
|
-
private
|
23
|
-
|
24
26
|
def self.find_root
|
25
27
|
cwd = Dir.pwd
|
26
28
|
return cwd if File.exists?(File.join(cwd, CONFIG_FILENAME))
|
data/lib/couch/actions/base.rb
CHANGED
@@ -1,6 +1,3 @@
|
|
1
|
-
require 'couch'
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
1
|
require 'thor/group'
|
5
2
|
require 'active_support/inflector'
|
6
3
|
|
@@ -9,21 +6,9 @@ module Couch
|
|
9
6
|
class Base < Thor::Group
|
10
7
|
include Thor::Actions
|
11
8
|
|
12
|
-
class_option :database, :type => :string
|
13
|
-
|
14
9
|
def self.banner
|
15
10
|
"couch #{to_s.split('::').last.underscore}"
|
16
11
|
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def database
|
21
|
-
options[:database] || Couch.database
|
22
|
-
end
|
23
|
-
|
24
|
-
def url_for(id)
|
25
|
-
File.join database, id
|
26
|
-
end
|
27
12
|
end
|
28
13
|
end
|
29
14
|
end
|
data/lib/couch/actions/pull.rb
CHANGED
@@ -1,47 +1,26 @@
|
|
1
|
-
require 'couch/actions/
|
1
|
+
require 'couch/actions/base'
|
2
|
+
require 'couch/design_document'
|
3
|
+
|
4
|
+
require "rest_client"
|
2
5
|
|
3
6
|
module Couch
|
4
7
|
module Actions
|
5
|
-
class Pull <
|
8
|
+
class Pull < Base
|
6
9
|
add_runtime_options!
|
7
10
|
|
8
11
|
def pull
|
9
|
-
|
10
|
-
url = url_for(id)
|
11
|
-
|
12
|
-
say "Pulling from %s..." % url
|
13
|
-
|
14
|
-
resp = RestClient.get url + "?attachments=true"
|
15
|
-
response = JSON.parse(resp.body)
|
16
|
-
map_doc(response)
|
17
|
-
rev = response["_rev"]
|
12
|
+
say "Pulling from %s" % DesignDocument.url
|
18
13
|
|
19
|
-
|
20
|
-
|
21
|
-
say "Error: Document %s does not exist!" % id
|
22
|
-
end
|
14
|
+
resp = RestClient.get DesignDocument.url(:attachments => true)
|
15
|
+
doc = DesignDocument.build_from_json(resp.body)
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
def map_doc(doc, dirname = destination_root)
|
27
|
-
doc.each do |key, value|
|
28
|
-
next if key == "_attachments"
|
29
|
-
filename = File.join(dirname, key)
|
30
|
-
if value.is_a?(String)
|
31
|
-
create_file "#{filename}.js", "#{value}\n"
|
32
|
-
else
|
33
|
-
Dir.mkdir(filename) unless File.directory?(filename)
|
34
|
-
map_doc value, File.join(dirname, key)
|
35
|
-
end
|
17
|
+
doc.write do |filename, content|
|
18
|
+
create_file filename, content
|
36
19
|
end
|
37
|
-
map_doc_attachments(doc["_attachments"], dirname) if doc["_attachments"]
|
38
|
-
end
|
39
20
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
create_file filename, value["data"].unpack("m")
|
44
|
-
end
|
21
|
+
say "Checked out %s" % doc.rev
|
22
|
+
rescue RestClient::ResourceNotFound
|
23
|
+
say "Error: Document %s does not exist!" % DesignDocument.id
|
45
24
|
end
|
46
25
|
end
|
47
26
|
end
|
data/lib/couch/actions/push.rb
CHANGED
@@ -1,21 +1,22 @@
|
|
1
|
-
require 'couch/actions/
|
1
|
+
require 'couch/actions/base'
|
2
|
+
require 'couch/design_document'
|
3
|
+
|
4
|
+
require "rest_client"
|
2
5
|
|
3
6
|
module Couch
|
4
7
|
module Actions
|
5
|
-
class Push <
|
8
|
+
class Push < Base
|
6
9
|
def create_database_unless_exists
|
7
|
-
RestClient.put database, nil
|
8
|
-
say "Created database %s" % database
|
10
|
+
RestClient.put DesignDocument.database, nil
|
11
|
+
say "Created database %s" % DesignDocument.database
|
9
12
|
rescue RestClient::PreconditionFailed
|
10
13
|
end
|
11
14
|
|
12
15
|
def push
|
13
|
-
doc =
|
14
|
-
|
15
|
-
|
16
|
-
say "Pushing to %s..." % url
|
16
|
+
doc = DesignDocument.build_from_filesystem(destination_root)
|
17
|
+
say "Pushing to %s" % DesignDocument.url
|
17
18
|
|
18
|
-
resp = RestClient.put url, doc.to_json
|
19
|
+
resp = RestClient.put DesignDocument.url, doc.to_json
|
19
20
|
response = JSON.parse(resp.body)
|
20
21
|
|
21
22
|
if response["ok"]
|
data/lib/couch/actions/routes.rb
CHANGED
@@ -26,15 +26,15 @@ module Couch
|
|
26
26
|
protected
|
27
27
|
|
28
28
|
def attachment_url(file)
|
29
|
-
File.join(database, '_design', File.basename(database), File.basename(file))
|
29
|
+
File.join(Couch.database, '_design', File.basename(Couch.database), File.basename(file))
|
30
30
|
end
|
31
31
|
|
32
32
|
def list_url(list, view)
|
33
|
-
File.join(database, '_design', File.basename(database), '_list', File.basename(view), File.basename(list, '.js'))
|
33
|
+
File.join(Couch.database, '_design', File.basename(Couch.database), '_list', File.basename(view), File.basename(list, '.js'))
|
34
34
|
end
|
35
35
|
|
36
36
|
def show_url(show, id = '/')
|
37
|
-
File.join(database, '_design', File.basename(database), '_show', File.basename(show, '.js'), id)
|
37
|
+
File.join(Couch.database, '_design', File.basename(Couch.database), '_show', File.basename(show, '.js'), id)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -0,0 +1,228 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module Couch
|
4
|
+
class DesignDocument
|
5
|
+
EXT_MIME_MAPPING = {
|
6
|
+
".html" => "text/html",
|
7
|
+
".js" => "text/javascript",
|
8
|
+
".css" => "text/css",
|
9
|
+
}
|
10
|
+
|
11
|
+
# initialize with a hash
|
12
|
+
def initialize(hash = {})
|
13
|
+
@hash = hash
|
14
|
+
end
|
15
|
+
|
16
|
+
# returns the id of the design document
|
17
|
+
def id
|
18
|
+
@hash["_id"]
|
19
|
+
end
|
20
|
+
|
21
|
+
# returns the rev of the design document
|
22
|
+
def rev
|
23
|
+
@hash["_rev"]
|
24
|
+
end
|
25
|
+
|
26
|
+
# converts to json
|
27
|
+
def to_json
|
28
|
+
hash_with_injected_makros.to_json
|
29
|
+
end
|
30
|
+
|
31
|
+
# write to filesystem
|
32
|
+
def write(&block)
|
33
|
+
write_doc @hash, nil, block
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
# returns new design document object from filesystem
|
38
|
+
def build_from_filesystem(root)
|
39
|
+
new map(root)
|
40
|
+
end
|
41
|
+
|
42
|
+
# returns new design document object from json string
|
43
|
+
def build_from_json(json)
|
44
|
+
new reject_makros(JSON.parse(json))
|
45
|
+
end
|
46
|
+
|
47
|
+
# returns the database used to store design document
|
48
|
+
def database
|
49
|
+
@database ||= Couch.database
|
50
|
+
end
|
51
|
+
|
52
|
+
# returns the id for design document
|
53
|
+
def id
|
54
|
+
@id ||= File.read(File.join(Couch.root, '_id.js')).strip
|
55
|
+
end
|
56
|
+
|
57
|
+
# returns the url for design document
|
58
|
+
def url(options = {})
|
59
|
+
File.join(database, id) << build_options_string(options)
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def reject_makros(doc)
|
65
|
+
# TODO: recursive walk libs
|
66
|
+
libs = doc["lib"]
|
67
|
+
return doc if libs.nil? || libs.empty?
|
68
|
+
# Attention: replace json makros first!
|
69
|
+
doc = reject_json_makros(doc, libs)
|
70
|
+
doc = reject_code_makros(doc, libs)
|
71
|
+
end
|
72
|
+
|
73
|
+
def reject_code_makros(doc, libs)
|
74
|
+
doc = doc.dup
|
75
|
+
doc.each do |key, value|
|
76
|
+
next if key == "lib"
|
77
|
+
if value.is_a?(String)
|
78
|
+
libs.each do |name, content|
|
79
|
+
# only substitute strings
|
80
|
+
next unless content.is_a?(String)
|
81
|
+
next unless value.include?(content.strip)
|
82
|
+
doc[key] = value.gsub(content.strip, "// !code #{name}.js")
|
83
|
+
end
|
84
|
+
elsif value.is_a?(Hash)
|
85
|
+
doc[key] = reject_code_makros(value, libs)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
doc
|
89
|
+
end
|
90
|
+
|
91
|
+
def reject_json_makros(doc, libs)
|
92
|
+
doc.each do |key, value|
|
93
|
+
next if key == "lib"
|
94
|
+
if value.is_a?(String)
|
95
|
+
libs.each do |name, content|
|
96
|
+
# only substitute strings
|
97
|
+
next unless content.is_a?(String)
|
98
|
+
json = 'var %s = %s;' % [name.sub(/\..*$/, ''), content.to_json]
|
99
|
+
next unless value.include?(json)
|
100
|
+
doc[key] = value.gsub(json, "// !json #{name}")
|
101
|
+
end
|
102
|
+
elsif value.is_a?(Hash)
|
103
|
+
doc[key] = reject_json_makros(value, libs)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
doc
|
107
|
+
end
|
108
|
+
|
109
|
+
def build_options_string(options)
|
110
|
+
return '' if options.empty?
|
111
|
+
options_array = []
|
112
|
+
options.each do |key, value|
|
113
|
+
options_array << URI.escape([key, value].join('='))
|
114
|
+
end
|
115
|
+
'?' + options_array.join("&")
|
116
|
+
end
|
117
|
+
|
118
|
+
def map(dirname, hash = {})
|
119
|
+
Dir.entries(dirname).each do |file|
|
120
|
+
next if file =~ /^\./
|
121
|
+
filename = File.join(dirname, file)
|
122
|
+
if file == "_attachments"
|
123
|
+
hash['_attachments'] = map_attachments(filename)
|
124
|
+
elsif File.directory?(filename)
|
125
|
+
hash[file] = map(filename)
|
126
|
+
elsif File.extname(filename) =~ /^\.(js|html)$/
|
127
|
+
# only .js and .html files are mapped
|
128
|
+
# but .js is stripped off the key
|
129
|
+
key = file.sub(/\.js$/, '')
|
130
|
+
hash[key] = File.read(filename).strip
|
131
|
+
end
|
132
|
+
end
|
133
|
+
hash
|
134
|
+
end
|
135
|
+
|
136
|
+
def map_attachments(dirname, hash = {}, keys = [])
|
137
|
+
Dir.entries(dirname).each do |file|
|
138
|
+
next if file =~ /^\./
|
139
|
+
filename = File.join(dirname, file)
|
140
|
+
base = keys + [file]
|
141
|
+
if File.directory?(filename)
|
142
|
+
map_attachments filename, hash, base
|
143
|
+
else
|
144
|
+
hash[base.join('/')] = {
|
145
|
+
"content_type" => mime_type(filename),
|
146
|
+
"data" => base64(File.read(filename)),
|
147
|
+
}
|
148
|
+
end
|
149
|
+
end
|
150
|
+
hash
|
151
|
+
end
|
152
|
+
|
153
|
+
# CouchDB needs base64 encodings without spaces
|
154
|
+
def base64(data)
|
155
|
+
[data].pack("m").gsub(/\s/,'')
|
156
|
+
end
|
157
|
+
|
158
|
+
# detect mime type from filename extension
|
159
|
+
def mime_type(filename)
|
160
|
+
ext = File.extname(filename)
|
161
|
+
EXT_MIME_MAPPING[ext] || 'text/plain'
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
def write_doc(doc, dirname, block)
|
168
|
+
doc.each do |key, value|
|
169
|
+
next if key == "_attachments"
|
170
|
+
filename = dirname ? File.join(dirname, key) : key.dup
|
171
|
+
if value.is_a?(String)
|
172
|
+
filename << ".js" unless File.extname(filename) == ".html"
|
173
|
+
block.call filename, "#{value}\n"
|
174
|
+
else
|
175
|
+
write_doc value, filename, block
|
176
|
+
end
|
177
|
+
end
|
178
|
+
write_attachments doc["_attachments"], dirname, block if doc["_attachments"]
|
179
|
+
end
|
180
|
+
|
181
|
+
def write_attachments(doc, dirname, block)
|
182
|
+
dirname = dirname ? File.join(dirname, "_attachments") : "_attachments"
|
183
|
+
|
184
|
+
doc.each do |key, value|
|
185
|
+
next unless value["data"]
|
186
|
+
|
187
|
+
block.call File.join(dirname, key), value["data"].unpack("m")
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
def hash_with_injected_makros
|
192
|
+
hash = inject_code_makros(@hash)
|
193
|
+
inject_json_makros(hash)
|
194
|
+
end
|
195
|
+
|
196
|
+
def inject_code_makros(doc)
|
197
|
+
doc.each do |key, value|
|
198
|
+
doc[key] = if value.is_a?(String)
|
199
|
+
value.gsub(/\/\/\s*!code.*$/) do |match|
|
200
|
+
filename = match.sub(/^.*!code\s*(\S+).*$/, '\1')
|
201
|
+
File.read(File.join(Couch.root, 'lib', filename)).strip
|
202
|
+
end
|
203
|
+
elsif value.is_a?(Hash)
|
204
|
+
inject_code_makros(value)
|
205
|
+
else
|
206
|
+
value
|
207
|
+
end
|
208
|
+
end
|
209
|
+
doc
|
210
|
+
end
|
211
|
+
|
212
|
+
def inject_json_makros(doc)
|
213
|
+
doc.each do |key, value|
|
214
|
+
doc[key] = if value.is_a?(String)
|
215
|
+
value.gsub(/\/\/\s*!json.*$/) do |match|
|
216
|
+
filename = match.sub(/^.*!json\s*(\S+).*$/, '\1')
|
217
|
+
'var %s = %s;' % [filename.sub(/\..*$/, ''), File.read(File.join(Couch.root, 'lib', filename)).strip.to_json]
|
218
|
+
end
|
219
|
+
elsif value.is_a?(Hash)
|
220
|
+
inject_json_makros(value)
|
221
|
+
else
|
222
|
+
value
|
223
|
+
end
|
224
|
+
end
|
225
|
+
doc
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
@@ -15,22 +15,29 @@ module Couch::Generators
|
|
15
15
|
copy_file "gitignore", ".gitignore" unless options[:skip_git]
|
16
16
|
template "_id.js"
|
17
17
|
copy_file "validate_doc_update.js"
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
empty_directory "lists"
|
19
|
+
empty_directory "shows"
|
20
|
+
empty_directory "updates"
|
21
|
+
empty_directory "views"
|
22
22
|
end
|
23
23
|
|
24
24
|
def create_attachments_files
|
25
25
|
empty_directory "_attachments"
|
26
26
|
inside "_attachments" do
|
27
|
-
|
28
|
-
|
27
|
+
empty_directory "images"
|
28
|
+
empty_directory "javascripts"
|
29
29
|
directory "stylesheets"
|
30
30
|
template "index.html"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def create_lib_files
|
35
|
+
empty_directory "lib"
|
36
|
+
inside "lib" do
|
37
|
+
copy_file "mustache/mustache.js", "mustache.js"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
34
41
|
protected
|
35
42
|
|
36
43
|
def app_name
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'rubygems'
|
2
1
|
require 'thor/group'
|
3
2
|
require 'active_support/inflector'
|
4
3
|
|
@@ -62,11 +61,6 @@ module Couch
|
|
62
61
|
end
|
63
62
|
end
|
64
63
|
end
|
65
|
-
|
66
|
-
def empty_directory_with_gitkeep(destination, config = {})
|
67
|
-
empty_directory(destination, config)
|
68
|
-
create_file("#{destination}/.gitkeep") unless options[:skip_git]
|
69
|
-
end
|
70
64
|
end
|
71
65
|
end
|
72
66
|
end
|
data/lib/couch/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
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-10 00:00:00 +01:00
|
18
18
|
default_executable: couch
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -74,20 +74,6 @@ dependencies:
|
|
74
74
|
version: 3.0.0.beta
|
75
75
|
type: :runtime
|
76
76
|
version_requirements: *id004
|
77
|
-
- !ruby/object:Gem::Dependency
|
78
|
-
name: rspec
|
79
|
-
prerelease: false
|
80
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
81
|
-
requirements:
|
82
|
-
- - ">="
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
segments:
|
85
|
-
- 1
|
86
|
-
- 2
|
87
|
-
- 9
|
88
|
-
version: 1.2.9
|
89
|
-
type: :development
|
90
|
-
version_requirements: *id005
|
91
77
|
description: With Couch you can easy build a standalone CouchDB application.
|
92
78
|
email: schmidt@netzmerk.com
|
93
79
|
executables:
|
@@ -99,6 +85,7 @@ extra_rdoc_files:
|
|
99
85
|
- README.rdoc
|
100
86
|
files:
|
101
87
|
- .gitignore
|
88
|
+
- .gitmodules
|
102
89
|
- LICENSE
|
103
90
|
- README.rdoc
|
104
91
|
- Rakefile
|
@@ -106,7 +93,6 @@ files:
|
|
106
93
|
- couch.gemspec
|
107
94
|
- lib/couch.rb
|
108
95
|
- lib/couch/actions/base.rb
|
109
|
-
- lib/couch/actions/net_base.rb
|
110
96
|
- lib/couch/actions/pull.rb
|
111
97
|
- lib/couch/actions/push.rb
|
112
98
|
- lib/couch/actions/routes.rb
|
@@ -116,6 +102,7 @@ files:
|
|
116
102
|
- lib/couch/commands/pull.rb
|
117
103
|
- lib/couch/commands/push.rb
|
118
104
|
- lib/couch/commands/routes.rb
|
105
|
+
- lib/couch/design_document.rb
|
119
106
|
- lib/couch/generators.rb
|
120
107
|
- lib/couch/generators/application/USAGE
|
121
108
|
- lib/couch/generators/application/application_generator.rb
|
@@ -142,11 +129,7 @@ files:
|
|
142
129
|
- lib/couch/generators/view/USAGE
|
143
130
|
- lib/couch/generators/view/templates/map.js
|
144
131
|
- lib/couch/generators/view/view_generator.rb
|
145
|
-
- lib/couch/mapper.rb
|
146
132
|
- lib/couch/version.rb
|
147
|
-
- spec/couch_spec.rb
|
148
|
-
- spec/spec.opts
|
149
|
-
- spec/spec_helper.rb
|
150
133
|
has_rdoc: true
|
151
134
|
homepage: http://github.com/jo/couch
|
152
135
|
licenses: []
|
@@ -177,6 +160,5 @@ rubygems_version: 1.3.6
|
|
177
160
|
signing_key:
|
178
161
|
specification_version: 3
|
179
162
|
summary: Standalone CouchDB Application Development Suite
|
180
|
-
test_files:
|
181
|
-
|
182
|
-
- spec/couch_spec.rb
|
163
|
+
test_files: []
|
164
|
+
|
@@ -1,21 +0,0 @@
|
|
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/mapper.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module Couch
|
2
|
-
class Mapper
|
3
|
-
MIME_TYPES = {
|
4
|
-
".html" => "text/html",
|
5
|
-
".js" => "text/javascript",
|
6
|
-
".css" => "text/css",
|
7
|
-
}
|
8
|
-
|
9
|
-
def initialize(root)
|
10
|
-
raise "Root invalid" unless root && File.directory?(root)
|
11
|
-
@root = root
|
12
|
-
end
|
13
|
-
|
14
|
-
def doc
|
15
|
-
map @root
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def map(dirname, hash = {})
|
21
|
-
Dir.entries(dirname).each do |file|
|
22
|
-
next if file =~ /^\./
|
23
|
-
filename = File.join(dirname, file)
|
24
|
-
if file == "_attachments"
|
25
|
-
hash['_attachments'] = map_attachments(filename)
|
26
|
-
elsif File.directory?(filename)
|
27
|
-
hash[file] = map(filename)
|
28
|
-
elsif File.extname(filename) == '.js'
|
29
|
-
# only .js files are mapped
|
30
|
-
key = file.sub(/\.js$/, '')
|
31
|
-
hash[key] = File.read(filename).strip
|
32
|
-
end
|
33
|
-
end
|
34
|
-
hash
|
35
|
-
end
|
36
|
-
|
37
|
-
def map_attachments(dirname, hash = {}, keys = [])
|
38
|
-
Dir.entries(dirname).each do |file|
|
39
|
-
next if file =~ /^\./
|
40
|
-
filename = File.join(dirname, file)
|
41
|
-
base = keys + [file]
|
42
|
-
if File.directory?(filename)
|
43
|
-
map_attachments filename, hash, base
|
44
|
-
else
|
45
|
-
hash[base.join('/')] = {
|
46
|
-
"content_type" => mime_type(filename),
|
47
|
-
"data" => base64(File.read(filename)),
|
48
|
-
}
|
49
|
-
end
|
50
|
-
end
|
51
|
-
hash
|
52
|
-
end
|
53
|
-
|
54
|
-
# CouchDB needs base64 encodings without spaces
|
55
|
-
def base64(data)
|
56
|
-
[data].pack("m").gsub(/\s/,'')
|
57
|
-
end
|
58
|
-
|
59
|
-
def mime_type(filename)
|
60
|
-
ext = File.extname(filename)
|
61
|
-
MIME_TYPES[ext] || 'text/plain'
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/spec/couch_spec.rb
DELETED
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|