manveru-ramaze 2009.04.08 → 2009.04.18
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +113 -0
- data/MANIFEST +2 -3
- data/Rakefile +5 -1
- data/bin/ramaze +107 -25
- data/examples/misc/rapp.rb +28 -17
- data/lib/proto/app.rb +15 -0
- data/lib/proto/config.ru +3 -4
- data/lib/proto/controller/init.rb +2 -2
- data/lib/proto/spec/main.rb +7 -8
- data/lib/proto/start.rb +6 -10
- data/lib/ramaze/contrib/email.rb +2 -0
- data/lib/ramaze/contrib/sequel/create_join.rb +1 -0
- data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
- data/lib/ramaze/contrib/sequel/image.rb +9 -11
- data/lib/ramaze/contrib/sequel/relation.rb +17 -3
- data/lib/ramaze/helper/localize.rb +13 -3
- data/lib/ramaze/helper/paginate.rb +1 -0
- data/lib/ramaze/request.rb +2 -1
- data/lib/ramaze/spec.rb +5 -8
- data/lib/ramaze/version.rb +1 -1
- data/lib/ramaze/view/haml.rb +1 -0
- data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
- data/lib/ramaze.rb +2 -0
- data/ramaze.gemspec +5 -5
- data/spec/examples/helpers/httpdigest.rb +42 -67
- data/spec/ramaze/dispatcher/file.rb +22 -20
- data/spec/ramaze/error.rb +1 -1
- data/spec/ramaze/helper/auth.rb +29 -40
- data/spec/ramaze/helper/flash.rb +10 -14
- data/spec/ramaze/helper/httpdigest.rb +47 -65
- data/spec/ramaze/helper/localize.rb +9 -9
- data/spec/ramaze/helper/simple_captcha.rb +9 -13
- data/spec/ramaze/helper/stack.rb +31 -39
- data/spec/ramaze/helper/user.rb +15 -13
- data/spec/ramaze/request.rb +12 -0
- data/tasks/release.rake +4 -22
- data/tasks/setup.rake +44 -0
- metadata +5 -6
- data/lib/proto/view/page.xhtml +0 -27
- data/lib/ramaze/snippets/string/each.rb +0 -19
- data/spec/ramaze/helper/partial.rb +0 -40
data/CHANGELOG
CHANGED
@@ -1,3 +1,116 @@
|
|
1
|
+
[afb3336 | Sat Apr 18 02:28:37 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
2
|
+
|
3
|
+
* Improve tasks a bit
|
4
|
+
|
5
|
+
[a4bbc31 | Fri Apr 17 02:37:14 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
6
|
+
|
7
|
+
* Only use /proc in bin/ramaze if possible, otherwise fall back to ps
|
8
|
+
|
9
|
+
Signed-off-by: Michael Fellinger <m.fellinger@gmail.com>
|
10
|
+
|
11
|
+
[35bf7c2 | Fri Apr 17 01:36:28 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
12
|
+
|
13
|
+
* Added status command and moved IRB.start inline instead of exec.
|
14
|
+
|
15
|
+
* Status needs testing on WIN32 and OSX
|
16
|
+
|
17
|
+
Signed-off-by: Michael Fellinger <m.fellinger@gmail.com>
|
18
|
+
|
19
|
+
[df495ae | Fri Apr 17 07:48:58 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
20
|
+
|
21
|
+
* Specify correct behaviour of Request#accept_language_with_weight
|
22
|
+
|
23
|
+
[7cee203 | Fri Apr 17 11:52:23 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
24
|
+
|
25
|
+
* Bring various Sequel specific stuff up to date
|
26
|
+
|
27
|
+
[21e2c4d | Thu Apr 16 03:01:32 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
28
|
+
|
29
|
+
* Defaults to webrick on port 7000 when starting now
|
30
|
+
|
31
|
+
Signed-off-by: Michael Fellinger <m.fellinger@gmail.com>
|
32
|
+
|
33
|
+
[bc09190 | Thu Apr 16 02:51:38 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
34
|
+
|
35
|
+
* Fixed "ramaze start" so it doesn't try and start a new instance
|
36
|
+
|
37
|
+
* added is_running? and check_running? as helpers
|
38
|
+
* refactored #stop to pass it's given pid to find_pid
|
39
|
+
|
40
|
+
Signed-off-by: Michael Fellinger <m.fellinger@gmail.com>
|
41
|
+
|
42
|
+
[c29043d | Thu Apr 16 12:47:02 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
43
|
+
|
44
|
+
* Adding app.rb to proto, explain new convention
|
45
|
+
|
46
|
+
[2e0d0ba | Thu Apr 16 03:33:16 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
47
|
+
|
48
|
+
* Make sure proto spec runs in right directory
|
49
|
+
|
50
|
+
[1a8c518 | Thu Apr 16 03:17:58 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
51
|
+
|
52
|
+
* Proto should use Etanni as well
|
53
|
+
|
54
|
+
[146a4d6 | Thu Apr 16 03:05:43 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
55
|
+
|
56
|
+
* Remove old layout from proto
|
57
|
+
|
58
|
+
[95e4e98 | Wed Apr 15 10:59:47 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
59
|
+
|
60
|
+
* Fix nagoro/render_partial, sorry for the mess
|
61
|
+
|
62
|
+
[9eb1cf0 | Wed Apr 15 10:59:10 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
63
|
+
|
64
|
+
* Remove String#each, we are compatible with Rack spec
|
65
|
+
|
66
|
+
[f95cdae | Wed Apr 15 02:12:02 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
67
|
+
|
68
|
+
* Use the render helper for nagoro/render_partial
|
69
|
+
|
70
|
+
[730b17f | Mon Apr 13 14:35:18 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
71
|
+
|
72
|
+
* Try to please the github syntax highlighter
|
73
|
+
|
74
|
+
[152aad6 | Mon Apr 13 04:58:24 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
75
|
+
|
76
|
+
* Rename Request#to_ivs to Request#to_instance_variables and add to_ivs alias for it
|
77
|
+
|
78
|
+
[425e8ff | Sat Apr 11 04:18:39 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
79
|
+
|
80
|
+
* Make Rapp example run
|
81
|
+
|
82
|
+
[518ab37 | Fri Apr 10 12:30:24 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
83
|
+
|
84
|
+
* Port specs to rack-test
|
85
|
+
|
86
|
+
* This breaks the spec for httpdigest helper since rack assumes that
|
87
|
+
plaintext auth consits of ['user:pass'].pack('m*') and we consider
|
88
|
+
plaintext auth as MD5 digest auth which includes the realm.
|
89
|
+
|
90
|
+
[18fabfc | Fri Apr 10 10:31:17 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
91
|
+
|
92
|
+
* Add a `rake setup` task that takes care of installing dependencies
|
93
|
+
|
94
|
+
[9567c23 | Thu Apr 09 11:00:33 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
95
|
+
|
96
|
+
* More improvments and fixes to the localize helper
|
97
|
+
|
98
|
+
[e0d48c3 | Thu Apr 09 11:00:03 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
99
|
+
|
100
|
+
* This should fix the contrib EmailHelper
|
101
|
+
|
102
|
+
[ed05392 | Wed Apr 08 09:19:29 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
103
|
+
|
104
|
+
* run Ramaze instead of Innate, just for better look
|
105
|
+
|
106
|
+
[97b1bd8 | Thu Apr 09 17:52:05 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
107
|
+
|
108
|
+
* Add ContentLength middleware
|
109
|
+
|
110
|
+
[591f1c0 | Tue Apr 07 17:15:59 UTC 2009] Michael Fellinger <m.fellinger@gmail.com>
|
111
|
+
|
112
|
+
* Version 2009.04.08
|
113
|
+
|
1
114
|
[e2a87c9 | Mon Apr 06 02:27:14 UTC 2009] TJ Vanderpoel <bougy.man@gmail.com>
|
2
115
|
|
3
116
|
* changed path search to use request.request_uri instead of request.fullpath, to handle fastcgi, mod_rack, and any other method where rack strips part of fullpath to derive request_uri
|
data/MANIFEST
CHANGED
@@ -182,6 +182,7 @@ examples/templates/view/external.rem
|
|
182
182
|
examples/templates/view/external.rhtml
|
183
183
|
examples/templates/view/external.tenjin
|
184
184
|
examples/templates/view/external.zmr
|
185
|
+
lib/proto/app.rb
|
185
186
|
lib/proto/config.ru
|
186
187
|
lib/proto/controller/init.rb
|
187
188
|
lib/proto/controller/main.rb
|
@@ -196,7 +197,6 @@ lib/proto/public/ramaze.png
|
|
196
197
|
lib/proto/spec/main.rb
|
197
198
|
lib/proto/start.rb
|
198
199
|
lib/proto/view/index.xhtml
|
199
|
-
lib/proto/view/page.xhtml
|
200
200
|
lib/ramaze.rb
|
201
201
|
lib/ramaze/app.rb
|
202
202
|
lib/ramaze/cache.rb
|
@@ -299,7 +299,6 @@ lib/ramaze/snippets/ramaze/fiber.rb
|
|
299
299
|
lib/ramaze/snippets/ramaze/struct.rb
|
300
300
|
lib/ramaze/snippets/string/camel_case.rb
|
301
301
|
lib/ramaze/snippets/string/color.rb
|
302
|
-
lib/ramaze/snippets/string/each.rb
|
303
302
|
lib/ramaze/snippets/string/end_with.rb
|
304
303
|
lib/ramaze/snippets/string/esc.rb
|
305
304
|
lib/ramaze/snippets/string/ord.rb
|
@@ -397,7 +396,6 @@ spec/ramaze/helper/localize.rb
|
|
397
396
|
spec/ramaze/helper/maruku.rb
|
398
397
|
spec/ramaze/helper/pager.rb
|
399
398
|
spec/ramaze/helper/paginate.rb
|
400
|
-
spec/ramaze/helper/partial.rb
|
401
399
|
spec/ramaze/helper/request_accessor.rb
|
402
400
|
spec/ramaze/helper/sequel_form.rb
|
403
401
|
spec/ramaze/helper/simple_captcha.rb
|
@@ -482,6 +480,7 @@ tasks/metric_changes.rake
|
|
482
480
|
tasks/rcov.rake
|
483
481
|
tasks/release.rake
|
484
482
|
tasks/reversion.rake
|
483
|
+
tasks/setup.rake
|
485
484
|
tasks/todo.rake
|
486
485
|
tasks/traits.rake
|
487
486
|
tasks/yard.rake
|
data/Rakefile
CHANGED
@@ -6,7 +6,11 @@ require 'rake/gempackagetask'
|
|
6
6
|
require 'time'
|
7
7
|
require 'date'
|
8
8
|
|
9
|
-
PROJECT_SPECS =
|
9
|
+
PROJECT_SPECS = FileList[
|
10
|
+
'spec/{contrib,examples,ramaze,snippets}/**/*.rb',
|
11
|
+
'lib/proto/spec/*.rb'
|
12
|
+
]
|
13
|
+
|
10
14
|
PROJECT_MODULE = 'Ramaze'
|
11
15
|
PROJECT_JQUERY_FILE = 'lib/proto/public/js/jquery.js'
|
12
16
|
PROJECT_README = 'README.markdown'
|
data/bin/ramaze
CHANGED
@@ -19,24 +19,28 @@ def usage
|
|
19
19
|
<<-TXT
|
20
20
|
Usage:
|
21
21
|
|
22
|
-
ramaze <start [PIDFILE]|stop [PIDFILE]|restart [PIDFILE]|create PROJECT|console> [ruby/rack options]
|
22
|
+
ramaze <start [PIDFILE]|stop [PIDFILE]|restart [PIDFILE]|status [PIDFILE]|create PROJECT|console> [ruby/rack options]
|
23
23
|
|
24
24
|
Commands:
|
25
|
-
|
26
|
-
|
25
|
+
* All commands which take an optional PIDFILE default to PROJECT.pid if you do not supply one.
|
26
|
+
* All commands which start a ramaze instance will default to webrick on port 7000 unless you supply
|
27
|
+
the rack options -p/--port PORT and/or * -s/--server SERVER.
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
start - Starts an instance of this application.
|
30
|
+
|
31
|
+
stop - Stops a running instance of this application.
|
30
32
|
|
31
33
|
restart - Stops running instance of this application, then starts it back up. Pidfile
|
32
34
|
(if supplied) is used for both stop and start.
|
33
35
|
|
36
|
+
status - Gives status of a running ramaze instance
|
37
|
+
|
34
38
|
create - Creates a new prototype Ramaze application in a directory named PROJECT in
|
35
39
|
the current directory. ramaze create foo would make ./foo containing an
|
36
|
-
application prototype. Rack options are
|
40
|
+
application prototype. Rack options are ignored here.
|
37
41
|
|
38
42
|
console - Starts an irb console with app.rb (and irb completion) loaded. This command
|
39
|
-
ignores rack options.
|
43
|
+
ignores rack options, ARGV is passed on to IRB.
|
40
44
|
|
41
45
|
Rack Options
|
42
46
|
#{%x{rackup --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")}
|
@@ -47,19 +51,24 @@ end
|
|
47
51
|
def start
|
48
52
|
# Find the name of this app
|
49
53
|
app_name = default_pidfile.sub(/\.pid$/,'')
|
54
|
+
added_args = []
|
50
55
|
if daemonize = OURARGS.detect { |arg| arg.match(/^(-[dD]|--daemonize)$/) }
|
51
56
|
if pid_arg = OURARGS.detect { |arg| arg.match(/^(-P|--pid)/) }
|
52
57
|
puts "User supplied pid: #{pid_arg}"
|
53
58
|
pid_file = OURARGS[OURARGS.index(pid_arg) + 1]
|
54
59
|
puts "Starting daemon with user defined pidfile: #{pid_file}"
|
55
|
-
exec("rackup", "config.ru", *ARGV)
|
56
60
|
else
|
57
|
-
puts "Starting daemon with default pidfile: #{default_pidfile}"
|
58
|
-
|
61
|
+
puts "Starting daemon with default pidfile: #{pid_file = default_pidfile}"
|
62
|
+
added_args += ["-P", pid_file]
|
63
|
+
end
|
64
|
+
if check_running?(pid_file)
|
65
|
+
$stderr.puts "Ramaze is already running with pidfile: #{pid_file}"
|
66
|
+
exit 127
|
59
67
|
end
|
60
|
-
else
|
61
|
-
exec("rackup", "config.ru", *ARGV)
|
62
68
|
end
|
69
|
+
added_args += ["-p", "7000"] unless OURARGS.detect { |arg| arg.match(/^(-p|--port)/) }
|
70
|
+
added_args += ["-s", "webrick"] unless OURARGS.detect { |arg| arg.match(/^(-s|--server)/) }
|
71
|
+
exec("rackup", "config.ru", *(ARGV + added_args))
|
63
72
|
end
|
64
73
|
|
65
74
|
def create(command)
|
@@ -84,34 +93,99 @@ def create(command)
|
|
84
93
|
end
|
85
94
|
|
86
95
|
def stop(command)
|
87
|
-
|
96
|
+
unless pid_file = find_pid(OURARGS[OURARGS.index(command) + 1])
|
97
|
+
$stderr.puts "No pid_file found! Cannot stop ramaze (may not be started)."
|
98
|
+
return false
|
99
|
+
end
|
88
100
|
pid = File.read(pid_file).to_i
|
89
|
-
puts "
|
101
|
+
puts "Stopping pid #{pid}"
|
90
102
|
Process.kill("INT", pid)
|
91
|
-
sleep
|
92
|
-
|
93
|
-
|
94
|
-
$stdout.puts "Process #{pid} did not die, forcing it with -9"
|
103
|
+
sleep 2
|
104
|
+
if is_running?(pid)
|
105
|
+
$stderr.puts "Process #{pid} did not die, forcing it with -9"
|
95
106
|
Process.kill(9, pid)
|
96
107
|
File.unlink(pid_file) if File.file?(pid_file)
|
97
108
|
true
|
98
|
-
|
109
|
+
else
|
99
110
|
File.unlink(pid_file) if File.file?(pid_file)
|
100
111
|
true
|
101
112
|
end
|
102
113
|
end
|
103
114
|
|
115
|
+
def status(command)
|
116
|
+
unless pid_file = find_pid(OURARGS[OURARGS.index(command) + 1])
|
117
|
+
$stderr.puts "No pid_file found! Ramaze may not be started."
|
118
|
+
exit 1
|
119
|
+
end
|
120
|
+
puts "Pid file #{pid_file} found, PID is #{pid = File.read(pid_file)}"
|
121
|
+
unless is_running?(pid.to_i)
|
122
|
+
$stderr.puts "PID #{pid} is not running"
|
123
|
+
exit 1
|
124
|
+
end
|
125
|
+
if Object.const_defined?("WIN32OLE")
|
126
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
127
|
+
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
128
|
+
processes.each { |p| ours << [p.Name, p.CommandLine, p.VirtualSize, p.CreationDate, p.ExecutablePath, p.Status ] }
|
129
|
+
puts "Ramaze is running!\n\tName: %s\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % ours.first
|
130
|
+
else
|
131
|
+
require "pathname"
|
132
|
+
# Check for /proc
|
133
|
+
if File.directory?(proc_dir = Pathname.new("/proc"))
|
134
|
+
proc_dir = proc_dir.join(pid)
|
135
|
+
# If we have a "stat" file, we'll assume linux and get as much info
|
136
|
+
# as we can
|
137
|
+
if File.file?(stat_file = proc_dir.join("stat"))
|
138
|
+
stats = File.read(stat_file).split
|
139
|
+
puts "Ramaze is running!\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % [
|
140
|
+
File.read(proc_dir.join("cmdline")).split("\000").join(" "),
|
141
|
+
"%s k" % (stats[22].to_f / 1024),
|
142
|
+
File.mtime(proc_dir),
|
143
|
+
File.readlink(proc_dir.join("exe")),
|
144
|
+
stats[2]
|
145
|
+
]
|
146
|
+
exit
|
147
|
+
end
|
148
|
+
end
|
149
|
+
# Fallthrough status, just print a ps
|
150
|
+
puts "Ramaze process #{pid} is running!"
|
151
|
+
begin
|
152
|
+
puts %x{ps l #{pid}}
|
153
|
+
rescue
|
154
|
+
puts "No further information available"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
104
159
|
## End Command methods }}}
|
105
160
|
|
106
161
|
# Helper methods {{{
|
107
162
|
def default_pidfile
|
108
163
|
return @default_pidfile if @default_pidfile
|
109
164
|
@default_pidfile = (File.basename(File.expand_path(ENV["PWD"])) + ".pid").strip
|
110
|
-
@default_pidfile
|
111
165
|
end
|
112
166
|
|
113
|
-
def
|
114
|
-
|
167
|
+
def is_running?(pid)
|
168
|
+
if Object.const_defined?("WIN32OLE")
|
169
|
+
wmi = WIN32OLE.connect("winmgmts://")
|
170
|
+
processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
|
171
|
+
processes.each { |process| ours << process.Name }
|
172
|
+
ours.first.nil?
|
173
|
+
else
|
174
|
+
begin
|
175
|
+
prio = Process.getpriority(Process::PRIO_PROCESS, pid)
|
176
|
+
true
|
177
|
+
rescue Errno::ESRCH
|
178
|
+
false
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def check_running?(pid_file)
|
184
|
+
return false unless File.file?(pid_file)
|
185
|
+
is_running?(File.read(pid_file).to_i)
|
186
|
+
end
|
187
|
+
|
188
|
+
def find_pid(pid_file)
|
115
189
|
if pid_file.nil? or not File.file?(pid_file)
|
116
190
|
pid_file = default_pidfile
|
117
191
|
end
|
@@ -125,7 +199,7 @@ end
|
|
125
199
|
## End helper methods }}}
|
126
200
|
|
127
201
|
OURARGS = ARGV.dup
|
128
|
-
command = ARGV.detect { |arg| arg.match(/^(?:--?)?(?:start|stop|restart|create|h(?:elp)?|v(?:ersion)?|console)/) }
|
202
|
+
command = ARGV.detect { |arg| arg.match(/^(?:--?)?(?:start|stop|restart|create|h(?:elp)?|v(?:ersion)?|console|status)/) }
|
129
203
|
if command.nil?
|
130
204
|
command = ""
|
131
205
|
else
|
@@ -133,6 +207,8 @@ else
|
|
133
207
|
end
|
134
208
|
|
135
209
|
case command
|
210
|
+
when /^(?:--?)?status$/
|
211
|
+
status(command)
|
136
212
|
when /^(?:--?)?restart$/
|
137
213
|
stop(command)
|
138
214
|
start
|
@@ -142,13 +218,19 @@ when /^(?:--?)?create$/
|
|
142
218
|
create(command)
|
143
219
|
when /^(?:--?)?stop$/
|
144
220
|
if stop(command)
|
145
|
-
puts "Ramazement has ended, go in peace"
|
221
|
+
puts "Ramazement has ended, go in peace."
|
146
222
|
$stdout.flush
|
147
223
|
else
|
148
224
|
puts "Ramaze failed to stop (or was not running)"
|
149
225
|
end
|
150
226
|
when /^(?:--?)?console$/
|
151
|
-
|
227
|
+
require "ramaze"
|
228
|
+
require "irb"
|
229
|
+
require "irb/completion"
|
230
|
+
Ramaze.options.started = true
|
231
|
+
require "start"
|
232
|
+
IRB.start
|
233
|
+
puts "Ramazement has ended, go in peace."
|
152
234
|
when /^(?:--?)?h(elp)?$/
|
153
235
|
puts usage
|
154
236
|
when /^(?:--?)?v(ersion)?$/
|
data/examples/misc/rapp.rb
CHANGED
@@ -4,10 +4,13 @@
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'ramaze'
|
6
6
|
require 'sequel'
|
7
|
+
require 'abbrev'
|
7
8
|
|
8
|
-
DB = Sequel.sqlite
|
9
|
+
DB = Sequel.sqlite
|
9
10
|
|
10
11
|
class Post < Sequel::Model
|
12
|
+
plugin :schema
|
13
|
+
plugin :hook_class_methods
|
11
14
|
set_schema{ primary_key :id; time :created_at; text :text }
|
12
15
|
before_create{ self.created_at ||= Time.now }
|
13
16
|
create_table
|
@@ -18,27 +21,35 @@ end
|
|
18
21
|
class MainController < Ramaze::Controller
|
19
22
|
def index
|
20
23
|
@posts = Post.order(:created_at.desc).first(10)
|
21
|
-
|
22
|
-
|
23
|
-
<
|
24
|
-
<
|
25
|
-
|
26
|
-
<
|
27
|
-
|
28
|
-
|
24
|
+
|
25
|
+
<<-'TEMPLATE'.strip
|
26
|
+
<html>
|
27
|
+
<head><title>Rapp</title></head>
|
28
|
+
<body>
|
29
|
+
<h1>Welcome to Rapp</h1>
|
30
|
+
<h2>A minimal chat wall</h2>
|
31
|
+
<p>Recent Posts:</p>
|
32
|
+
<div id="posts" class="container">
|
33
|
+
<?r @posts.each do |post| ?>
|
34
|
+
<div id="post-#{post.id}" class="post">
|
35
|
+
<p class="text">#{post.text}</p>
|
36
|
+
<p class="created">#{post.created_at}</p>
|
37
|
+
</div>
|
38
|
+
<?r end ?>
|
29
39
|
</div>
|
30
|
-
|
31
|
-
|
32
|
-
<
|
33
|
-
<
|
34
|
-
|
35
|
-
|
36
|
-
</
|
40
|
+
<p>Post Something:</p>
|
41
|
+
<form action="#{r(:create)}" method="POST">
|
42
|
+
<input type="text" size="40" name="text" />
|
43
|
+
<input type="submit" value="Post Message!" />
|
44
|
+
</form>
|
45
|
+
</body>
|
46
|
+
</html>
|
47
|
+
TEMPLATE
|
37
48
|
end
|
38
49
|
|
39
50
|
def create
|
40
51
|
Post.create(:text => request[:text])
|
41
|
-
redirect
|
52
|
+
redirect r(:/)
|
42
53
|
end
|
43
54
|
end
|
44
55
|
|
data/lib/proto/app.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This file contains your application, it requires dependencies and necessary
|
2
|
+
# parts of the application.
|
3
|
+
#
|
4
|
+
# It will be required from either `config.ru` or `start.rb`
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'ramaze'
|
8
|
+
|
9
|
+
# Add the directory this file resides in to the load path, so you can run the
|
10
|
+
# app from any other working directory
|
11
|
+
$LOAD_PATH.unshift(__DIR__)
|
12
|
+
|
13
|
+
# Initialize controllers and models
|
14
|
+
require 'model/init'
|
15
|
+
require 'controller/init'
|
data/lib/proto/config.ru
CHANGED
@@ -11,7 +11,6 @@
|
|
11
11
|
# application as FastCGI, CGI, or standalone with Mongrel or WEBrick—all from
|
12
12
|
# the same configuration.
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
Ramaze
|
17
|
-
run Innate
|
14
|
+
require File.expand_path('app', File.dirname(__FILE__))
|
15
|
+
Ramaze.start(:file => __FILE__, :started => true)
|
16
|
+
run Ramaze
|
data/lib/proto/spec/main.rb
CHANGED
@@ -2,21 +2,20 @@ require 'ramaze'
|
|
2
2
|
require 'ramaze/spec'
|
3
3
|
|
4
4
|
require __DIR__('../start')
|
5
|
+
Ramaze.options.roots = __DIR__('../')
|
5
6
|
|
6
7
|
describe MainController do
|
7
8
|
behaves_like :mock
|
8
9
|
|
9
10
|
should 'show start page' do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
got.body.should =~ /<h1>Welcome to Ramaze!<\/h1>/
|
11
|
+
get('/').status.should == 200
|
12
|
+
last_response['Content-Type'].should == 'text/html'
|
13
|
+
last_response.should =~ /<h1>Welcome to Ramaze!<\/h1>/
|
14
14
|
end
|
15
15
|
|
16
16
|
should 'show /notemplate' do
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
got.body.should =~ /there is no 'notemplate.xhtml' associated with this action/
|
17
|
+
get('/notemplate').status.should == 200
|
18
|
+
last_response['Content-Type'].should == 'text/html'
|
19
|
+
last_response.should =~ /there is no 'notemplate\.xhtml' associated with this action/
|
21
20
|
end
|
22
21
|
end
|
data/lib/proto/start.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# Use this file directly like `ruby start.rb` if you don't want to use the
|
2
|
+
# `ramaze start` command.
|
3
|
+
# All application related things should go into `app.rb`, this file is simply
|
4
|
+
# for options related to running the application locally.
|
3
5
|
|
4
|
-
|
5
|
-
# app from any other working directory
|
6
|
-
$LOAD_PATH.unshift(__DIR__)
|
6
|
+
require File.expand_path('app', File.dirname(__FILE__))
|
7
7
|
|
8
|
-
|
9
|
-
require 'controller/init'
|
10
|
-
require 'model/init'
|
11
|
-
|
12
|
-
Ramaze.start(:adapter => :webrick, :port => 7000) if __FILE__ == $0
|
8
|
+
Ramaze.start(:adapter => :webrick, :port => 7000, :file => __FILE__)
|
data/lib/ramaze/contrib/email.rb
CHANGED
@@ -94,14 +94,14 @@ class FormField
|
|
94
94
|
select(gestalt)
|
95
95
|
else
|
96
96
|
case db_type
|
97
|
-
when
|
97
|
+
when /varchar|integer/
|
98
98
|
input(gestalt)
|
99
|
-
when
|
99
|
+
when /boolean/
|
100
100
|
checkbox(gestalt)
|
101
|
-
when
|
101
|
+
when /string/
|
102
102
|
textarea(gestalt)
|
103
103
|
else
|
104
|
-
raise
|
104
|
+
raise("Unsupported type: (%p : %p)" % [db_type || hint, field])
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
# Usage:
|
8
8
|
# class Avatar < Sequel::Model
|
9
9
|
# IMAGE = {
|
10
|
-
# # specifies
|
10
|
+
# # specifies many_to_one, will create relation and foreign key
|
11
11
|
#
|
12
12
|
# :owner => :User,
|
13
13
|
#
|
@@ -51,8 +51,8 @@
|
|
51
51
|
module SequelImage
|
52
52
|
def self.included(model)
|
53
53
|
args = model::IMAGE
|
54
|
-
set_foreign_key = args[:foreign_key]
|
55
|
-
|
54
|
+
set_foreign_key = args[:foreign_key] || "#{args[:owner]}_id".downcase.to_sym
|
55
|
+
set_many_to_one = args[:many_to_one] || args[:owner].to_s.downcase.to_sym
|
56
56
|
|
57
57
|
# Define schema
|
58
58
|
model.set_schema do
|
@@ -68,21 +68,19 @@ module SequelImage
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Define Relations
|
71
|
-
model.
|
71
|
+
model.many_to_one set_many_to_one
|
72
72
|
|
73
73
|
# Define Hooks
|
74
|
-
model.
|
75
|
-
|
76
|
-
model.before_create do
|
74
|
+
model.before_create :generate_thumbnails do
|
77
75
|
generate_thumbnails
|
78
76
|
self.created_at = Time.now
|
79
77
|
end
|
80
78
|
|
81
|
-
model.before_save do
|
79
|
+
model.before_save :update_time do
|
82
80
|
self.updated_at = Time.now
|
83
81
|
end
|
84
82
|
|
85
|
-
model.before_destroy do
|
83
|
+
model.before_destroy :cleanup do
|
86
84
|
cleanup if conf[:cleanup]
|
87
85
|
end
|
88
86
|
|
@@ -110,7 +108,7 @@ module SequelImage
|
|
110
108
|
tempfile = file[:tempfile]
|
111
109
|
raise ArgumentError, 'Empty tempfile' if tempfile.size == 0
|
112
110
|
|
113
|
-
ext =
|
111
|
+
ext = Rack::Mime::MIME_TYPES.invert[type]
|
114
112
|
image.mime = type
|
115
113
|
target_name = image.next_name(File.basename(filename, File.extname(filename)), ext)
|
116
114
|
target_path = File.join(image.public_root, image.path, target_name)
|
@@ -150,7 +148,7 @@ module SequelImage
|
|
150
148
|
end
|
151
149
|
|
152
150
|
def public_root
|
153
|
-
Ramaze
|
151
|
+
Ramaze.options.roots.first
|
154
152
|
end
|
155
153
|
|
156
154
|
def filename(size)
|