capcode-base-couchrest 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-couchrest
2
+
3
+ Capcode plugin to access CouchDB via CouchRest
@@ -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-couchrest"
8
+ gem.summary = %Q{Capcode plugin to access CouchDB via CouchRest}
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('couchrest')
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,46 @@
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-couchrest}
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 CouchRest}
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-couchrest.gemspec",
24
+ "examples/blog-couchdb-CR.rb",
25
+ "lib/capcode/base/couchrest.rb"
26
+ ]
27
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-base-couchrest}
28
+ s.rdoc_options = ["--charset=UTF-8"]
29
+ s.require_paths = ["lib"]
30
+ s.rubygems_version = %q{1.3.5}
31
+ s.summary = %q{Capcode plugin to access CouchDB via CouchRest}
32
+
33
+ if s.respond_to? :specification_version then
34
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
35
+ s.specification_version = 3
36
+
37
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
38
+ s.add_runtime_dependency(%q<couchrest>, [">= 0"])
39
+ else
40
+ s.add_dependency(%q<couchrest>, [">= 0"])
41
+ end
42
+ else
43
+ s.add_dependency(%q<couchrest>, [">= 0"])
44
+ end
45
+ end
46
+
@@ -0,0 +1,311 @@
1
+ $:.unshift( "../lib" )
2
+ require 'rubygems'
3
+ require 'capcode'
4
+ require 'capcode/base/couch'
5
+ require 'capcode/render/markaby'
6
+
7
+ class User < Capcode::Base
8
+ include Capcode::Resource
9
+
10
+ property :login, :type => String
11
+ property :passwd, :type => String
12
+ end
13
+
14
+ class Story < Capcode::Base
15
+ include Capcode::Resource
16
+
17
+ property :title, :type => String
18
+ property :body, :type => String
19
+ property :create_at, :type => Date
20
+
21
+ property :user_id
22
+
23
+ view_by :create_at, :descending => true
24
+ end
25
+
26
+ module Capcode
27
+ class HTTPError
28
+ def r404(f)
29
+ @file = f
30
+ end
31
+ end
32
+
33
+ class Style < Route '/styles.css'
34
+ STYLE = File.read(__FILE__).gsub(/.*__END__/m, '')
35
+
36
+ def get
37
+ @response['Content-Type'] = 'text/css; charset=utf-8'
38
+ STYLE
39
+ end
40
+ end
41
+
42
+ class Index < Route '/'
43
+ def get
44
+ @story = Story.find( :all )
45
+
46
+ render( :markaby => :home, :layout => :my_layout )
47
+ end
48
+ end
49
+
50
+ class Remove < Route '/remove/([^\/]*)/(.*)'
51
+ def get( id, rev )
52
+ Story.delete(id, rev)
53
+ redirect( Index )
54
+ end
55
+ end
56
+
57
+ class Add < Route '/add'
58
+ def get
59
+ if session[:user]
60
+ @story = Story.new()
61
+ render( :markaby => :add, :layout => :my_layout )
62
+ else
63
+ redirect( Login )
64
+ end
65
+ end
66
+ def post
67
+ if session[:user]
68
+ s = Story.create( :title => params['title'], :body => params['body'], :create_at => Time.now, :user_id => session[:user] )
69
+ redirect( Index )
70
+ else
71
+ redirect( Login )
72
+ end
73
+ end
74
+ end
75
+
76
+ class Edit < Route '/edit/(.*)'
77
+ def get( id )
78
+ if session[:user]
79
+ @story = Story.find( id )
80
+ render( :markaby => :add, :layout => :my_layout )
81
+ else
82
+ redirect( Index )
83
+ end
84
+ end
85
+ def post( id )
86
+ # story = Story.find( params['id'] )
87
+ story = Story.find( id )
88
+ story.title = params['title']
89
+ story.body = params['body']
90
+ story.save
91
+
92
+ redirect( Index )
93
+ end
94
+ end
95
+
96
+ class Login < Route '/login'
97
+ def get
98
+ if session[:user]
99
+ redirect( Index )
100
+ else
101
+ render( :markaby => :login, :layout => :my_layout )
102
+ end
103
+ end
104
+ def post
105
+ u = User.by_login_and_passwd( params['login'], params['passwd'] )
106
+ unless u.nil?
107
+ session[:user] = u.id
108
+ end
109
+ redirect( Index )
110
+ end
111
+ end
112
+
113
+ class Logout < Route '/logout'
114
+ def get
115
+ session[:user] = nil
116
+ redirect( Index )
117
+ end
118
+ end
119
+ end
120
+
121
+ module Capcode::Views
122
+ def r404
123
+ p "Pas glop !!! #{@file} est inconnu !!!"
124
+ end
125
+
126
+ def home
127
+ @story.each do |s|
128
+ h2 s.title
129
+ p.info do
130
+ _post_menu(s)
131
+ text " #{s.create_at} by " #.strftime('%B %M, %Y @ %H:%M ')
132
+ i s.user.login
133
+ end
134
+ text s.body
135
+ end
136
+ end
137
+
138
+ def add
139
+ form :method => "POST" do
140
+ text "Titre :"
141
+ input :type => "text", :name => "title", :value => @story.title; br
142
+ textarea :name => "body" do; @story.body; end; br
143
+ input :type => "submit"
144
+ # input :type => "hidden", :name => "id", :value => @story.id
145
+ end
146
+ end
147
+
148
+ def login
149
+ form :method => "POST" do
150
+ table do
151
+ tr do
152
+ td "Login :"
153
+ td {input :type => "text", :name => "login"}
154
+ end
155
+ tr do
156
+ td "Password :"
157
+ td {input :type => "text", :name => "passwd"}
158
+ end
159
+ end
160
+ input :type => "submit", :value => "Login"
161
+ end
162
+ end
163
+
164
+ def my_layout
165
+ html do
166
+ head do
167
+ title 'My Blog'
168
+ link :rel => 'stylesheet', :type => 'text/css', :href => '/styles.css', :media => 'screen'
169
+ end
170
+ body do
171
+ h1 { a 'My Blog', :href => URL(Capcode::Index) }
172
+
173
+ div.wrapper! do
174
+ yield
175
+ end
176
+
177
+ p.footer! do
178
+ if session[:user]
179
+ a 'New', :href => URL(Capcode::Add)
180
+ text "|"
181
+ a "Logout", :href => URL(Capcode::Logout)
182
+ else
183
+ a 'Login', :href => URL(Capcode::Login)
184
+ end
185
+ text ' &ndash; Powered by '
186
+ a 'Capcode', :href => 'http://capcode.rubyforge.org'
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+ def _post_menu(post)
193
+ if session[:user]
194
+ text '['
195
+ a "Del", :href => URL( Capcode::Remove, post.id, post.rev )
196
+ text '|'
197
+ a "Edit", :href => URL( Capcode::Edit, post.id )
198
+ text ']'
199
+ end
200
+ end
201
+
202
+ end
203
+
204
+ #Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-couchdb.yml" ) do |c|
205
+ # admin = User.find_by_login( "admin" )
206
+ # if admin.nil?
207
+ # puts "Create admin user..."
208
+ # admin = User.create( :login => "admin", :passwd => "admin" )
209
+ # end
210
+ # puts "Admin user : \n\tlogin = #{admin.login}\n\tpassword = #{admin.passwd}"
211
+ #end
212
+
213
+ __END__
214
+ * {
215
+ margin: 0;
216
+ padding: 0;
217
+ }
218
+
219
+ body {
220
+ font: normal 14px Arial, 'Bitstream Vera Sans', Helvetica, sans-serif;
221
+ line-height: 1.5;
222
+ }
223
+
224
+ h1, h2, h3, h4 {
225
+ font-family: Georgia, serif;
226
+ font-weight: normal;
227
+ }
228
+
229
+ h1 {
230
+ background-color: #EEE;
231
+ border-bottom: 5px solid #f06000;
232
+ outline: 5px solid #ab250c;
233
+ font-weight: normal;
234
+ font-size: 3em;
235
+ padding: 0.5em 0;
236
+ text-align: center;
237
+ }
238
+
239
+ h1 a { color: #143D55; text-decoration: none }
240
+ h1 a:hover { color: #143D55; text-decoration: underline }
241
+
242
+ h2 {
243
+ font-size: 2em;
244
+ color: #287AA9;
245
+ }
246
+
247
+ #wrapper {
248
+ margin: 3em auto;
249
+ width: 700px;
250
+ }
251
+
252
+ p {
253
+ margin-bottom: 1em;
254
+ }
255
+
256
+ p.info, p#footer {
257
+ color: #999;
258
+ margin-left: 1em;
259
+ }
260
+
261
+ p.info a, p#footer a {
262
+ color: #999;
263
+ }
264
+
265
+ p.info a:hover, p#footer a:hover {
266
+ text-decoration: none;
267
+ }
268
+
269
+ a {
270
+ color: #6F812D;
271
+ }
272
+
273
+ a:hover {
274
+ color: #9CB441;
275
+ }
276
+
277
+ hr {
278
+ border-width: 5px 0;
279
+ border-style: solid;
280
+ border-color: #9CB441;
281
+ border-bottom-color: #6F812D;
282
+ height: 0;
283
+ }
284
+
285
+ p#footer {
286
+ font-size: 0.9em;
287
+ margin: 0;
288
+ padding: 1em;
289
+ text-align: center;
290
+ }
291
+
292
+ label {
293
+ display: inline-block;
294
+ width: 100%;
295
+ }
296
+
297
+ input, textarea {
298
+ margin-bottom: 1em;
299
+ width: 200px;
300
+ }
301
+
302
+ input.submit {
303
+ float: left;
304
+ width: auto;
305
+ }
306
+
307
+ textarea {
308
+ font: normal 14px Arial, 'Bitstream Vera Sans', Helvetica, sans-serif;
309
+ height: 300px;
310
+ width: 400px;
311
+ }
@@ -0,0 +1,25 @@
1
+ require 'rubygems'
2
+ begin
3
+ require 'couchrest'
4
+ rescue LoadError => e
5
+ raise Capcode::MissingLibrary, "CouchRest 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
+ class Base < CouchRest::ExtendedDocument
15
+ use_database @db
16
+ end
17
+
18
+ class << self
19
+ def db_connect( dbfile, logfile )
20
+ dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
21
+ @db = CouchRest.database!("#{dbconfig[:host]}/#{dbconfig[:database]}")
22
+ # TODO: Add logger
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-base-couchrest
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: couchrest
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 CouchRest
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-couchrest.gemspec
39
+ - examples/blog-couchdb-CR.rb
40
+ - lib/capcode/base/couchrest.rb
41
+ has_rdoc: true
42
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-base-couchrest
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --charset=UTF-8
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.5
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Capcode plugin to access CouchDB via CouchRest
69
+ test_files: []
70
+