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