Capcode 0.8.8 → 0.8.9

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.
@@ -0,0 +1,101 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>File: redirect.rb</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href="../../../.././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="fileHeader">
50
+ <h1>redirect.rb</h1>
51
+ <table class="header-table">
52
+ <tr class="top-aligned-row">
53
+ <td><strong>Path:</strong></td>
54
+ <td>lib/capcode/render/redirect.rb
55
+ </td>
56
+ </tr>
57
+ <tr class="top-aligned-row">
58
+ <td><strong>Last Update:</strong></td>
59
+ <td>Sun Nov 08 19:52:37 +0100 2009</td>
60
+ </tr>
61
+ </table>
62
+ </div>
63
+ <!-- banner header -->
64
+
65
+ <div id="bodyContent">
66
+
67
+
68
+
69
+ <div id="contextContent">
70
+
71
+
72
+
73
+ </div>
74
+
75
+
76
+ </div>
77
+
78
+
79
+ <!-- if includes -->
80
+
81
+ <div id="section">
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+ <!-- if method_list -->
91
+
92
+
93
+ </div>
94
+
95
+
96
+ <div id="validator-badges">
97
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
98
+ </div>
99
+
100
+ </body>
101
+ </html>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Nov 05 14:46:36 +0100 2009</td>
59
+ <td>Fri Dec 11 21:04:01 +0100 2009</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -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
+ $:.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 ' &ndash; 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,3 @@
1
+ host: localhost
2
+ port: 27017
3
+ database: my_blog
@@ -5,7 +5,8 @@ require 'capcode/render/markaby'
5
5
  module Capcode
6
6
  class Index < Route '/'
7
7
  def get
8
- render :markaby => :index
8
+ @time = Time.now()
9
+ render :markaby => :index, :layout => :glop
9
10
  end
10
11
  end
11
12
  end
@@ -21,6 +22,7 @@ module Capcode::Views
21
22
 
22
23
  def index
23
24
  h1 "Hello !"
25
+ p "il est #{@time}"
24
26
  end
25
27
  end
26
28