capcode-base-couch_foo 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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 glejeune
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = capcode-base-couch_foo
2
+
3
+ Capcode plugin to access CouchDB via couch_foo
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capcode-base-couch_foo"
8
+ gem.summary = %Q{Capcode plugin to access CouchDB via couch_foo}
9
+ gem.description = gem.summary
10
+ gem.email = "gregoire.lejeune@free.fr"
11
+ gem.homepage = "http://github.com/glejeune/Capcode.more/tree/master/%s" % gem.name
12
+ gem.authors = ["Gregoire Lejeune"]
13
+
14
+ gem.add_dependency('couch_foo')
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,49 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capcode-base-couch_foo}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gregoire Lejeune"]
12
+ s.date = %q{2010-01-07}
13
+ s.description = %q{Capcode plugin to access CouchDB via couch_foo}
14
+ s.email = %q{gregoire.lejeune@free.fr}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "capcode-base-couch_foo.gemspec",
24
+ "examples/blog-couchdb-run.rb",
25
+ "examples/blog-couchdb.rb",
26
+ "examples/blog-couchdb.ru",
27
+ "examples/blog-couchdb.yml",
28
+ "lib/capcode/base/couch_foo.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-base-couch_foo}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.5}
34
+ s.summary = %q{Capcode plugin to access CouchDB via couch_foo}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<couch_foo>, [">= 0"])
42
+ else
43
+ s.add_dependency(%q<couch_foo>, [">= 0"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<couch_foo>, [">= 0"])
47
+ end
48
+ end
49
+
@@ -0,0 +1,10 @@
1
+ require 'blog-couchdb'
2
+
3
+ Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-couchdb.yml" ) do |c|
4
+ admin = User.find_by_login( "admin" )
5
+ if admin.nil?
6
+ puts "Create admin user..."
7
+ admin = User.create( :login => "admin", :passwd => "admin" )
8
+ end
9
+ puts "Admin user : \n\tlogin = #{admin.login}\n\tpassword = #{admin.passwd}"
10
+ end
@@ -0,0 +1,314 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ require 'capcode/render/markaby'
4
+ $:.unshift( "../lib" )
5
+ require 'capcode/base/couch_foo'
6
+
7
+ class User < Capcode::Base
8
+ include Capcode::Resource
9
+
10
+ property :login, String
11
+ property :passwd, String
12
+
13
+ has_many :stories
14
+ end
15
+
16
+ class Story < Capcode::Base
17
+ include Capcode::Resource
18
+
19
+ property :title, String
20
+ property :body, String
21
+ property :create_at, String
22
+
23
+ property :user_id, String
24
+ belongs_to :user
25
+
26
+ default_sort :create_at
27
+ end
28
+
29
+ module Capcode
30
+ class HTTPError
31
+ def r404(f)
32
+ @file = f
33
+ end
34
+ end
35
+
36
+ class Style < Route '/styles.css'
37
+ STYLE = File.read(__FILE__).gsub(/.*__END__/m, '')
38
+
39
+ def get
40
+ @response['Content-Type'] = 'text/css; charset=utf-8'
41
+ STYLE
42
+ end
43
+ end
44
+
45
+ class Index < Route '/'
46
+ def get
47
+ @story = Story.find( :all )
48
+
49
+ render( :markaby => :home, :layout => :my_layout )
50
+ end
51
+ end
52
+
53
+ class Remove < Route '/remove/([^\/]*)/(.*)'
54
+ def get( id, rev )
55
+ Story.delete(id, rev)
56
+ redirect( Index )
57
+ end
58
+ end
59
+
60
+ class Add < Route '/add'
61
+ def get
62
+ if session[:user]
63
+ @story = Story.new()
64
+ render( :markaby => :add, :layout => :my_layout )
65
+ else
66
+ redirect( Login )
67
+ end
68
+ end
69
+ def post
70
+ if session[:user]
71
+ s = Story.create( :title => params['title'], :body => params['body'], :create_at => Time.now, :user_id => session[:user] )
72
+ redirect( Index )
73
+ else
74
+ redirect( Login )
75
+ end
76
+ end
77
+ end
78
+
79
+ class Edit < Route '/edit/(.*)'
80
+ def get( id )
81
+ if session[:user]
82
+ @story = Story.find( id )
83
+ render( :markaby => :add, :layout => :my_layout )
84
+ else
85
+ redirect( Index )
86
+ end
87
+ end
88
+ def post( id )
89
+ # story = Story.find( params['id'] )
90
+ story = Story.find( id )
91
+ story.title = params['title']
92
+ story.body = params['body']
93
+ story.save
94
+
95
+ redirect( Index )
96
+ end
97
+ end
98
+
99
+ class Login < Route '/login'
100
+ def get
101
+ if session[:user]
102
+ redirect( Index )
103
+ else
104
+ render( :markaby => :login, :layout => :my_layout )
105
+ end
106
+ end
107
+ def post
108
+ u = User.find_by_login_and_passwd( params['login'], params['passwd'] )
109
+ unless u.nil?
110
+ session[:user] = u.id
111
+ end
112
+ redirect( Index )
113
+ end
114
+ end
115
+
116
+ class Logout < Route '/logout'
117
+ def get
118
+ session[:user] = nil
119
+ redirect( Index )
120
+ end
121
+ end
122
+ end
123
+
124
+ module Capcode::Views
125
+ def r404
126
+ p "Pas glop !!! #{@file} est inconnu !!!"
127
+ end
128
+
129
+ def home
130
+ @story.each do |s|
131
+ h2 s.title
132
+ p.info do
133
+ _post_menu(s)
134
+ text " #{s.create_at} by " #.strftime('%B %M, %Y @ %H:%M ')
135
+ i s.user.login
136
+ end
137
+ text s.body
138
+ end
139
+ end
140
+
141
+ def add
142
+ form :method => "POST" do
143
+ text "Titre :"
144
+ input :type => "text", :name => "title", :value => @story.title; br
145
+ textarea :name => "body" do; @story.body; end; br
146
+ input :type => "submit"
147
+ # input :type => "hidden", :name => "id", :value => @story.id
148
+ end
149
+ end
150
+
151
+ def login
152
+ form :method => "POST" do
153
+ table do
154
+ tr do
155
+ td "Login :"
156
+ td {input :type => "text", :name => "login"}
157
+ end
158
+ tr do
159
+ td "Password :"
160
+ td {input :type => "text", :name => "passwd"}
161
+ end
162
+ end
163
+ input :type => "submit", :value => "Login"
164
+ end
165
+ end
166
+
167
+ def my_layout
168
+ html do
169
+ head do
170
+ title 'My Blog'
171
+ link :rel => 'stylesheet', :type => 'text/css', :href => '/styles.css', :media => 'screen'
172
+ end
173
+ body do
174
+ h1 { a 'My Blog', :href => URL(Capcode::Index) }
175
+
176
+ div.wrapper! do
177
+ yield
178
+ end
179
+
180
+ p.footer! do
181
+ if session[:user]
182
+ a 'New', :href => URL(Capcode::Add)
183
+ text "|"
184
+ a "Logout", :href => URL(Capcode::Logout)
185
+ else
186
+ a 'Login', :href => URL(Capcode::Login)
187
+ end
188
+ text ' &ndash; Powered by '
189
+ a 'Capcode', :href => 'http://capcode.rubyforge.org'
190
+ end
191
+ end
192
+ end
193
+ end
194
+
195
+ def _post_menu(post)
196
+ if session[:user]
197
+ text '['
198
+ a "Del", :href => URL( Capcode::Remove, post.id, post.rev )
199
+ text '|'
200
+ a "Edit", :href => URL( Capcode::Edit, post.id )
201
+ text ']'
202
+ end
203
+ end
204
+
205
+ end
206
+
207
+ #Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-couchdb.yml" ) do |c|
208
+ # admin = User.find_by_login( "admin" )
209
+ # if admin.nil?
210
+ # puts "Create admin user..."
211
+ # admin = User.create( :login => "admin", :passwd => "admin" )
212
+ # end
213
+ # puts "Admin user : \n\tlogin = #{admin.login}\n\tpassword = #{admin.passwd}"
214
+ #end
215
+
216
+ __END__
217
+ * {
218
+ margin: 0;
219
+ padding: 0;
220
+ }
221
+
222
+ body {
223
+ font: normal 14px Arial, 'Bitstream Vera Sans', Helvetica, sans-serif;
224
+ line-height: 1.5;
225
+ }
226
+
227
+ h1, h2, h3, h4 {
228
+ font-family: Georgia, serif;
229
+ font-weight: normal;
230
+ }
231
+
232
+ h1 {
233
+ background-color: #EEE;
234
+ border-bottom: 5px solid #f06000;
235
+ outline: 5px solid #ab250c;
236
+ font-weight: normal;
237
+ font-size: 3em;
238
+ padding: 0.5em 0;
239
+ text-align: center;
240
+ }
241
+
242
+ h1 a { color: #143D55; text-decoration: none }
243
+ h1 a:hover { color: #143D55; text-decoration: underline }
244
+
245
+ h2 {
246
+ font-size: 2em;
247
+ color: #287AA9;
248
+ }
249
+
250
+ #wrapper {
251
+ margin: 3em auto;
252
+ width: 700px;
253
+ }
254
+
255
+ p {
256
+ margin-bottom: 1em;
257
+ }
258
+
259
+ p.info, p#footer {
260
+ color: #999;
261
+ margin-left: 1em;
262
+ }
263
+
264
+ p.info a, p#footer a {
265
+ color: #999;
266
+ }
267
+
268
+ p.info a:hover, p#footer a:hover {
269
+ text-decoration: none;
270
+ }
271
+
272
+ a {
273
+ color: #6F812D;
274
+ }
275
+
276
+ a:hover {
277
+ color: #9CB441;
278
+ }
279
+
280
+ hr {
281
+ border-width: 5px 0;
282
+ border-style: solid;
283
+ border-color: #9CB441;
284
+ border-bottom-color: #6F812D;
285
+ height: 0;
286
+ }
287
+
288
+ p#footer {
289
+ font-size: 0.9em;
290
+ margin: 0;
291
+ padding: 1em;
292
+ text-align: center;
293
+ }
294
+
295
+ label {
296
+ display: inline-block;
297
+ width: 100%;
298
+ }
299
+
300
+ input, textarea {
301
+ margin-bottom: 1em;
302
+ width: 200px;
303
+ }
304
+
305
+ input.submit {
306
+ float: left;
307
+ width: auto;
308
+ }
309
+
310
+ textarea {
311
+ font: normal 14px Arial, 'Bitstream Vera Sans', Helvetica, sans-serif;
312
+ height: 300px;
313
+ width: 400px;
314
+ }
@@ -0,0 +1,12 @@
1
+ require 'blog-couchdb'
2
+
3
+ app = Capcode.application( :db_config => "blog-couchdb.yml" ) do |c|
4
+ admin = User.find_by_login( "admin" )
5
+ if admin.nil?
6
+ puts "Create admin user..."
7
+ admin = User.create( :login => "admin", :passwd => "admin" )
8
+ end
9
+ puts "Log as admin with : \n\tlogin = #{admin.login}\n\tpassword = #{admin.passwd}"
10
+ end
11
+
12
+ run app
@@ -0,0 +1,2 @@
1
+ host: http://localhost:5984
2
+ database: my_blog
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ begin
3
+ require 'couch_foo'
4
+ rescue LoadError => e
5
+ raise Capcode::MissingLibrary, "CouchFoo could not be loaded (is it installed?): #{e.message}"
6
+ end
7
+ require 'yaml'
8
+ require 'logger'
9
+
10
+ module Capcode
11
+ module Resource
12
+ end
13
+
14
+ Base = CouchFoo::Base
15
+
16
+ class << self
17
+ def db_connect( dbfile, logfile )
18
+ dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
19
+ Base.set_database(dbconfig)
20
+ Base.logger = Logger.new(logfile)
21
+ end
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-base-couch_foo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregoire Lejeune
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-07 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: couch_foo
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Capcode plugin to access CouchDB via couch_foo
26
+ email: gregoire.lejeune@free.fr
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - capcode-base-couch_foo.gemspec
39
+ - examples/blog-couchdb-run.rb
40
+ - examples/blog-couchdb.rb
41
+ - examples/blog-couchdb.ru
42
+ - examples/blog-couchdb.yml
43
+ - lib/capcode/base/couch_foo.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-base-couch_foo
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Capcode plugin to access CouchDB via couch_foo
72
+ test_files: []
73
+