Capcode 0.8.9 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +13 -1
- data/doc/rdoc/classes/Capcode.html +410 -545
- data/doc/rdoc/classes/Capcode/Configuration.html +263 -0
- data/doc/rdoc/classes/Capcode/Helpers.html +154 -345
- data/doc/rdoc/classes/Capcode/Helpers/Authorization.html +6 -6
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/README_rdoc.html +42 -2
- data/doc/rdoc/files/lib/capcode/configuration_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode/render/text_rb.html +1 -1
- data/doc/rdoc/files/lib/capcode_rb.html +14 -1
- data/doc/rdoc/fr_class_index.html +1 -1
- data/doc/rdoc/fr_file_index.html +0 -13
- data/doc/rdoc/fr_method_index.html +12 -14
- data/examples/render-image.rb +1 -1
- data/examples/render-text.rb +4 -1
- data/examples/rest.rb +1 -0
- data/examples/sample.rb +5 -3
- data/examples/upload.rb +1 -0
- data/lib/capcode.rb +45 -61
- data/lib/capcode/configuration.rb +69 -34
- data/lib/capcode/render/text.rb +1 -1
- data/lib/capcode/version.rb +1 -1
- metadata +31 -106
- data/doc/rdoc/classes/Capcode/Mab.html +0 -118
- data/doc/rdoc/files/lib/capcode/render/binary_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/email_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/erb_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/haml_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/json_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/markaby_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/mustache_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/none_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/redirect_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/sass_rb.html +0 -108
- data/doc/rdoc/files/lib/capcode/render/static_rb.html +0 -101
- data/doc/rdoc/files/lib/capcode/render/webdav_rb.html +0 -124
- data/doc/rdoc/files/lib/capcode/render/xml_rb.html +0 -101
- data/examples/auth-webdav.rb +0 -29
- data/examples/blog-ar.rb +0 -81
- data/examples/blog-ar.yml +0 -3
- data/examples/blog-couchdb-run.rb +0 -10
- data/examples/blog-couchdb.rb +0 -314
- data/examples/blog-couchdb.ru +0 -12
- data/examples/blog-couchdb.yml +0 -2
- data/examples/blog-dm.rb +0 -63
- data/examples/blog-dm.yml +0 -2
- data/examples/blog-mongodb-run.rb +0 -10
- data/examples/blog-mongodb.rb +0 -304
- data/examples/blog-mongodb.yml +0 -3
- data/examples/blog-sq.rb +0 -82
- data/examples/blog-sq.yml +0 -3
- data/examples/mail/mail_html.rhtml +0 -1
- data/examples/mail/mail_text.rhtml +0 -1
- data/examples/mail/ok.rhtml +0 -1
- data/examples/mail/rubyfr.png +0 -0
- data/examples/mustache/with_class.mustache +0 -8
- data/examples/mustache/without_class.mustache +0 -1
- data/examples/render-binary.rb +0 -46
- data/examples/render-email.rb +0 -68
- data/examples/render-erb.rb +0 -19
- data/examples/render-haml_sass.rb +0 -26
- data/examples/render-json.rb +0 -13
- data/examples/render-markaby.rb +0 -29
- data/examples/render-mustache.rb +0 -30
- data/examples/render-redirect.rb +0 -19
- data/examples/render-static.rb +0 -21
- data/examples/render-static.ru +0 -19
- data/examples/render-use.rb +0 -32
- data/examples/render-webdav.rb +0 -26
- data/examples/render-xml.rb +0 -24
- data/examples/rss.rb +0 -48
- data/examples/static/coderay.css +0 -131
- data/examples/static/index.html +0 -24
- data/examples/test/index.html +0 -1
- data/lib/capcode/base/ar.rb +0 -54
- data/lib/capcode/base/couchdb.rb +0 -23
- data/lib/capcode/base/dm.rb +0 -33
- data/lib/capcode/base/mongodb.rb +0 -27
- data/lib/capcode/base/sq.rb +0 -58
- data/lib/capcode/render/binary.rb +0 -8
- data/lib/capcode/render/email.rb +0 -73
- data/lib/capcode/render/erb.rb +0 -59
- data/lib/capcode/render/haml.rb +0 -60
- data/lib/capcode/render/json.rb +0 -14
- data/lib/capcode/render/markaby.rb +0 -38
- data/lib/capcode/render/mustache.rb +0 -37
- data/lib/capcode/render/none.rb +0 -7
- data/lib/capcode/render/redirect.rb +0 -7
- data/lib/capcode/render/sass.rb +0 -48
- data/lib/capcode/render/static.rb +0 -14
- data/lib/capcode/render/webdav.rb +0 -49
- data/lib/capcode/render/xml.rb +0 -119
data/examples/blog-couchdb.rb
DELETED
@@ -1,314 +0,0 @@
|
|
1
|
-
$:.unshift( "../lib" )
|
2
|
-
require 'rubygems'
|
3
|
-
require 'capcode'
|
4
|
-
require 'capcode/base/couchdb'
|
5
|
-
require 'capcode/render/markaby'
|
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 ' – 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
|
-
}
|
data/examples/blog-couchdb.ru
DELETED
@@ -1,12 +0,0 @@
|
|
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
|
data/examples/blog-couchdb.yml
DELETED
data/examples/blog-dm.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
$:.unshift( "../lib" )
|
2
|
-
require 'rubygems'
|
3
|
-
require 'capcode'
|
4
|
-
require 'capcode/base/dm'
|
5
|
-
|
6
|
-
class Story < Capcode::Base
|
7
|
-
include Capcode::Resource
|
8
|
-
|
9
|
-
property :id, Integer, :serial => true
|
10
|
-
property :title, String
|
11
|
-
property :body, String
|
12
|
-
property :date, String
|
13
|
-
end
|
14
|
-
|
15
|
-
module Capcode
|
16
|
-
class HTTPError
|
17
|
-
def r404(f)
|
18
|
-
"Pas glop !!! #{f} est inconnu !!!"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class Index < Route '/'
|
23
|
-
def get
|
24
|
-
r = "<html><body>"
|
25
|
-
|
26
|
-
story = Story.all
|
27
|
-
|
28
|
-
story.each do |s|
|
29
|
-
r += "<h2>#{s.title}</h2><small>#{s.date} - <a href='#{URL( Remove, s.id )}'>Delete this entry</a></small><p>#{s.body}</p>"
|
30
|
-
end
|
31
|
-
|
32
|
-
r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class Remove < Route '/remove/([^\/]*)'
|
37
|
-
def get( id )
|
38
|
-
Story.get!(id).destroy
|
39
|
-
redirect( Index )
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class Add < Route '/add'
|
44
|
-
def get
|
45
|
-
'
|
46
|
-
<html><body>
|
47
|
-
<h1>Add a new entry</h1>
|
48
|
-
<form method="POST">
|
49
|
-
Titre : <input type="text" name="title"><br />
|
50
|
-
<textarea name="body"></textarea><br />
|
51
|
-
<input type="submit">
|
52
|
-
</form>
|
53
|
-
</body></html>
|
54
|
-
'
|
55
|
-
end
|
56
|
-
def post
|
57
|
-
Story.new( :title => params['title'], :body => params['body'], :date => Time.now.to_s ).save
|
58
|
-
redirect( Index )
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-dm.yml" )
|
data/examples/blog-dm.yml
DELETED
@@ -1,10 +0,0 @@
|
|
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
|
data/examples/blog-mongodb.rb
DELETED
@@ -1,304 +0,0 @@
|
|
1
|
-
$:.unshift( "../lib" )
|
2
|
-
require 'rubygems'
|
3
|
-
require 'capcode'
|
4
|
-
require 'capcode/base/mongodb'
|
5
|
-
require 'capcode/render/markaby'
|
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
|
-
}
|