manveru-ramaze 2009.04 → 2009.04.01

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/CHANGELOG +0 -405
  2. data/MANIFEST +16 -16
  3. data/Rakefile +4 -24
  4. data/bin/ramaze +52 -275
  5. data/doc/tutorial/todolist.html +5 -83
  6. data/doc/tutorial/todolist.txt +33 -85
  7. data/examples/app/auth/layout/{auth.xhtml → auth.nag} +0 -0
  8. data/examples/app/auth/view/{index.xhtml → index.nag} +0 -0
  9. data/examples/app/auth/view/{login.xhtml → login.nag} +0 -0
  10. data/examples/app/auth/view/{secret.xhtml → secret.nag} +0 -0
  11. data/examples/app/blog/app.rb +1 -1
  12. data/examples/app/blog/controller/comment.rb +1 -1
  13. data/examples/app/blog/controller/entry.rb +3 -12
  14. data/examples/app/blog/model/init.rb +0 -5
  15. data/examples/app/blog/model/tag.rb +2 -2
  16. data/examples/app/blog/start.rb +1 -1
  17. data/examples/app/blog/view/entry/index.nag +3 -3
  18. data/examples/app/blog/view/feed.atom.nag +1 -1
  19. data/examples/app/blog/view/feed.rss.nag +1 -1
  20. data/examples/app/blog/view/index.nag +1 -1
  21. data/examples/app/blog/view/tag/index.nag +1 -1
  22. data/examples/app/todolist/model/init.rb +0 -3
  23. data/examples/app/wikore/spec/wikore.rb +6 -4
  24. data/examples/app/wikore/src/controller.rb +11 -9
  25. data/examples/app/wikore/src/model.rb +10 -7
  26. data/examples/app/wikore/start.rb +1 -1
  27. data/examples/app/wikore/{view → template}/index.xhtml +0 -0
  28. data/examples/helpers/provide.rb +23 -0
  29. data/examples/misc/rapp.rb +17 -28
  30. data/examples/templates/template_redcloth.rb +2 -2
  31. data/examples/templates/template_xslt.rb +48 -0
  32. data/examples/templates/view/external.xsl +57 -0
  33. data/lib/proto/config.ru +5 -4
  34. data/lib/proto/controller/init.rb +2 -2
  35. data/lib/proto/layout/{default.xhtml → default.nag} +0 -0
  36. data/lib/proto/spec/main.rb +8 -7
  37. data/lib/proto/start.rb +10 -6
  38. data/lib/proto/view/{index.xhtml → index.nag} +0 -0
  39. data/lib/proto/view/page.nag +27 -0
  40. data/lib/ramaze/app.rb +5 -5
  41. data/lib/ramaze/cache.rb +2 -3
  42. data/lib/ramaze/contrib/email.rb +0 -2
  43. data/lib/ramaze/contrib/sequel/create_join.rb +0 -1
  44. data/lib/ramaze/contrib/sequel/fill.rb +12 -0
  45. data/lib/ramaze/contrib/sequel/form_field.rb +4 -4
  46. data/lib/ramaze/contrib/sequel/image.rb +11 -9
  47. data/lib/ramaze/contrib/sequel/relation.rb +3 -17
  48. data/lib/ramaze/controller/default.rb +0 -5
  49. data/lib/ramaze/helper/cache.rb +8 -22
  50. data/lib/ramaze/helper/formatting.rb +0 -2
  51. data/lib/ramaze/helper/httpdigest.rb +1 -1
  52. data/lib/ramaze/helper/link.rb +5 -2
  53. data/lib/ramaze/helper/localize.rb +3 -13
  54. data/lib/ramaze/helper/paginate.rb +0 -1
  55. data/lib/ramaze/helper/partial.rb +10 -85
  56. data/lib/ramaze/helper.rb +16 -6
  57. data/lib/ramaze/request.rb +1 -22
  58. data/lib/ramaze/snippets/ramaze/deprecated.rb +1 -0
  59. data/lib/ramaze/snippets/string/each.rb +19 -0
  60. data/lib/ramaze/spec.rb +2 -9
  61. data/lib/ramaze/version.rb +1 -1
  62. data/lib/ramaze/view/haml.rb +0 -1
  63. data/lib/ramaze/view/liquid.rb +11 -45
  64. data/lib/ramaze/view/nagoro/render_partial.rb +9 -9
  65. data/lib/ramaze/view.rb +0 -4
  66. data/lib/ramaze.rb +0 -2
  67. data/ramaze.gemspec +12 -12
  68. data/spec/contrib/sequel/fill.rb +47 -0
  69. data/spec/examples/helpers/httpdigest.rb +67 -42
  70. data/spec/examples/templates/template_markaby.rb +1 -1
  71. data/spec/examples/templates/template_xslt.rb +10 -0
  72. data/spec/ramaze/dispatcher/file.rb +20 -22
  73. data/spec/ramaze/error.rb +1 -1
  74. data/spec/ramaze/helper/auth.rb +40 -29
  75. data/spec/ramaze/helper/cache.rb +3 -43
  76. data/spec/ramaze/helper/flash.rb +14 -10
  77. data/spec/ramaze/helper/httpdigest.rb +65 -47
  78. data/spec/ramaze/helper/localize.rb +9 -9
  79. data/spec/ramaze/helper/partial.rb +40 -0
  80. data/spec/ramaze/helper/sequel_form.rb +1 -1
  81. data/spec/ramaze/helper/simple_captcha.rb +13 -9
  82. data/spec/ramaze/helper/stack.rb +39 -31
  83. data/spec/ramaze/helper/user.rb +13 -15
  84. data/spec/ramaze/request.rb +0 -12
  85. data/tasks/bacon.rake +21 -38
  86. data/tasks/release.rake +22 -4
  87. metadata +24 -22
  88. data/lib/proto/app.rb +0 -15
  89. data/lib/ramaze/cache/localmemcache.rb +0 -56
  90. data/lib/ramaze/contrib/app_graph.rb +0 -64
  91. data/lib/ramaze/tool/create.rb +0 -48
  92. data/lib/ramaze/tool/project_creator.rb +0 -111
  93. data/spec/ramaze/cache/localmemcache.rb +0 -49
  94. data/tasks/setup.rake +0 -24
data/bin/ramaze CHANGED
@@ -1,303 +1,80 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- def include_ramaze
3
+ begin
4
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
5
+ require 'ramaze'
6
+ rescue LoadError
7
+ $:.shift
8
+
4
9
  begin
5
- $:.unshift File.join(File.dirname(__FILE__), '/../lib')
6
- require 'ramaze'
10
+ require 'rubygems'
7
11
  rescue LoadError
8
- $:.shift
9
-
10
- begin
11
- require 'rubygems'
12
- rescue LoadError
13
- end
14
- require 'ramaze'
15
12
  end
13
+ require 'ramaze'
16
14
  end
17
15
 
18
- def usage
19
- txt = <<-TXT
20
- Usage:
21
-
22
- ramaze <start [PIDFILE]|stop [PIDFILE]|restart [PIDFILE]|status [PIDFILE]|create PROJECT|console> [ruby/rack options]
23
-
24
- Commands:
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.
28
-
29
- start - Starts an instance of this application.
30
-
31
- stop - Stops a running instance of this application.
32
-
33
- restart - Stops running instance of this application, then starts it back up. Pidfile
34
- (if supplied) is used for both stop and start.
16
+ additions = lambda do |op|
17
+ op.separator ''
18
+ op.separator 'Specialized options:'
35
19
 
36
- status - Gives status of a running ramaze instance
37
-
38
- create - Creates a new prototype Ramaze application in a directory named PROJECT in
39
- the current directory. ramaze create foo would make ./foo containing an
40
- application prototype. Rack options are ignored here.
41
-
42
- console - Starts an irb console with app.rb (and irb completion) loaded. This command
43
- ignores rack options, ARGV is passed on to IRB.
44
- TXT
45
- if is_windows?
46
- txt << %x{ruby #{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
47
- else
48
- txt << %x{#{rackup_path} --help}.split("\n").reject { |line| line.match(/^Usage:/) }.join("\n\t")
20
+ op.on('--create PROJECT', 'New application from proto') do |project_name|
21
+ require 'ramaze/tool/create'
22
+ Ramaze::Tool::Create.create(project_name)
23
+ exit
49
24
  end
50
- end
51
25
 
52
- ## Methods for commands {{{
53
- def start
54
- # Find the name of this app
55
- app_name = default_pidfile.sub(/\.pid$/,'')
56
- added_args = []
57
- if daemonize = OURARGS.detect { |arg| arg.match(/^(-[dD]|--daemonize)$/) }
58
- if pid_arg = OURARGS.detect { |arg| arg.match(/^(-P|--pid)/) }
59
- puts "User supplied pid: #{pid_arg}"
60
- pid_file = OURARGS[OURARGS.index(pid_arg) + 1]
61
- puts "Starting daemon with user defined pidfile: #{pid_file}"
62
- else
63
- puts "Starting daemon with default pidfile: #{pid_file = default_pidfile}"
64
- added_args += ["-P", pid_file]
65
- end
66
- if check_running?(pid_file)
67
- $stderr.puts "Ramaze is already running with pidfile: #{pid_file}"
68
- exit 127
69
- end
70
- end
71
- added_args += ["-p", "7000"] unless OURARGS.detect { |arg| arg.match(/^(-p|--port)/) }
72
- added_args += ["-s", "webrick"] unless OURARGS.detect { |arg| arg.match(/^(-s|--server)/) }
73
- if is_windows?
74
- exec("ruby", rackup_path.to_s, "config.ru", *(ARGV + added_args))
75
- else
76
- exec(rackup_path.to_s, "config.ru", *(ARGV + added_args))
26
+ op.on('-i', '--instant', "Start up with bare-bones Controller") do |instant|
27
+ require 'ramaze/controller/main'
77
28
  end
78
- end
79
-
80
- def create(command)
81
- project_name = OURARGS[OURARGS.index(command) + 1]
82
- if project_name.nil?
83
- $stderr.puts "Must supply a project name" if project_name.nil?
84
- puts usage
85
- exit 1
86
- end
87
- opts = {}
88
- if OURARGS.detect { |arg| arg.match(/^(--force)/) }
89
- puts "Overwriting any existing files as requested."
90
- opts[:force] = true
91
- end
92
- if OURARGS.detect { |arg| arg.match(/^(--amend)/) }
93
- puts "Only amending missing files as requested."
94
- opts[:amend] = true
95
- end
96
- include_ramaze
97
- require 'ramaze/tool/create'
98
- Ramaze::Tool::Create.create(project_name, opts)
99
- end
100
29
 
101
- def stop(command)
102
- unless pid_file = find_pid(OURARGS[OURARGS.index(command) + 1])
103
- $stderr.puts "No pid_file found! Cannot stop ramaze (may not be started)."
104
- return false
105
- end
106
- pid = File.read(pid_file).to_i
107
- puts "Stopping pid #{pid}"
108
- Process.kill("INT", pid)
109
- sleep 2
110
- if is_running?(pid)
111
- $stderr.puts "Process #{pid} did not die, forcing it with -9"
112
- Process.kill(9, pid)
113
- File.unlink(pid_file) if File.file?(pid_file)
114
- true
115
- else
116
- File.unlink(pid_file) if File.file?(pid_file)
117
- true
118
- end
119
- end
120
-
121
- def status(command)
122
- unless pid_file = find_pid(OURARGS[OURARGS.index(command) + 1])
123
- $stderr.puts "No pid_file found! Ramaze may not be started."
124
- exit 1
125
- end
126
- puts "Pid file #{pid_file} found, PID is #{pid = File.read(pid_file)}"
127
- unless is_running?(pid.to_i)
128
- $stderr.puts "PID #{pid} is not running"
129
- exit 1
130
- end
131
- if is_windows?
132
- wmi = WIN32OLE.connect("winmgmts://")
133
- processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
134
- processes.each { |p| ours << [p.Name, p.CommandLine, p.VirtualSize, p.CreationDate, p.ExecutablePath, p.Status ] }
135
- 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
136
- else
137
- require "pathname"
138
- # Check for /proc
139
- if File.directory?(proc_dir = Pathname.new("/proc"))
140
- proc_dir = proc_dir.join(pid)
141
- # If we have a "stat" file, we'll assume linux and get as much info
142
- # as we can
143
- if File.file?(stat_file = proc_dir.join("stat"))
144
- stats = File.read(stat_file).split
145
- puts "Ramaze is running!\n\tCommand Line: %s\n\tVirtual Size: %s\n\tStarted: %s\n\tExec Path: %s\n\tStatus: %s" % [
146
- File.read(proc_dir.join("cmdline")).split("\000").join(" "),
147
- "%s k" % (stats[22].to_f / 1024),
148
- File.mtime(proc_dir),
149
- File.readlink(proc_dir.join("exe")),
150
- stats[2]
151
- ]
152
- exit
153
- end
154
- end
155
- # Fallthrough status, just print a ps
156
- puts "Ramaze process #{pid} is running!"
157
- begin
158
- puts %x{ps l #{pid}}
159
- rescue
160
- puts "No further information available"
161
- end
30
+ op.on('-e', '--execute STRING', String, "Execute string instead of a start.rb.") do |execute|
31
+ eval execute
162
32
  end
163
33
  end
164
34
 
165
- ## End Command methods }}}
35
+ runner = ARGV.reverse.find{|arg| File.file?(arg) }
36
+ runner ||= 'start.rb' if File.file?('start.rb')
166
37
 
167
- # Helper methods {{{
168
- def default_pidfile
169
- return @default_pidfile if @default_pidfile
170
- require "pathname"
171
- @default_pidfile = (Pathname.new(".").expand_path.basename.to_s + ".pid").strip
172
- end
38
+ if runner
39
+ overlay = {
40
+ :root => File.dirname(runner),
41
+ :runner => runner, :origin => :console,
42
+ }
173
43
 
174
- def is_windows?
175
- return @is_win if @is_win
176
- begin
177
- require "win32ole"
178
- rescue LoadError
44
+ [overlay, ENV, ARGV].each do |opt|
45
+ Ramaze::Global.merge!(opt, &additions)
179
46
  end
180
- @is_win ||= Object.const_defined?("WIN32OLE")
181
- end
182
47
 
183
- def rackup_path
184
- return @rackup_path if @rackup_path
185
- # Use the supplied path if the user supplied -R
186
- if path_supplied = ARGV.delete("-R")
187
- @rackup_path = ARGV.delete(OURARGS[OURARGS.index("-R") + 1])
188
- if @rackup_path and File.file?(@rackup_path)
189
- return @rackup_path
190
- else
191
- $stderr.puts "rackup does not exist at #{@rackup_path} (given with -R)"
192
- end
193
- end
194
- # Check with 'which' on platforms which support it
195
- unless is_windows?
196
- @rackup_path = %x{which rackup}.to_s.chomp
197
- if @rackup_path.size > 0 and File.file?(@rackup_path)
198
- return @rackup_path
199
- end
200
- end
201
- # check for rackup in RUBYLIB
202
- libs = ENV["RUBYLIB"].to_s.split(is_windows? ? ";" : ":")
203
- if rack_lib = libs.detect { |r| r.match %r<(\\|/)rack\1> }
204
- require "pathname"
205
- @rackup_path = Pathname.new(rack_lib).parent.join("bin").join("rackup").expand_path
206
- return @rackup_path if File.file?(@rackup_path)
207
- end
208
- begin
209
- require "rubygems"
210
- require "rack"
211
- require "pathname"
212
- @rackup_path = Pathname.new(Gem.bindir).join("rackup").to_s
213
- return @rackup_path if File.file?(@rackup_path)
214
- rescue LoadError
215
- nil
216
- end
217
- @rackup_path = nil
218
- raise "Cannot find path to rackup, please supply full path to rackup with -R"
219
- end
48
+ runner = File.expand_path(runner)
49
+
50
+ console = Ramaze::Global.console
220
51
 
221
- def is_running?(pid)
222
- if is_windows?
223
- wmi = WIN32OLE.connect("winmgmts://")
224
- processes, ours = wmi.ExecQuery("select * from win32_process where ProcessId = #{pid}"), []
225
- processes.each { |process| ours << process.Name }
226
- ours.first.nil?
227
- else
228
- begin
229
- prio = Process.getpriority(Process::PRIO_PROCESS, pid)
230
- true
231
- rescue Errno::ESRCH
232
- false
233
- end
234
- end
235
- end
52
+ if console
53
+ ARGV.clear #Avoid passing args to IRB
236
54
 
237
- def check_running?(pid_file)
238
- return false unless File.file?(pid_file)
239
- is_running?(File.read(pid_file).to_i)
240
- end
241
-
242
- def find_pid(pid_file)
243
- if pid_file.nil? or not File.file?(pid_file)
244
- pid_file = default_pidfile
245
- end
246
- unless File.file?(pid_file)
247
- $stderr.puts "Could not find running process id."
248
- return false
249
- end
250
- pid_file
251
- end
55
+ Ramaze.trait[:started] = true
56
+ require runner
252
57
 
253
- ## End helper methods }}}
58
+ require 'irb'
59
+ require 'irb/completion'
254
60
 
255
- OURARGS = ARGV.dup
256
- command = ARGV.detect { |arg| arg.match(/^(?:--?)?(?:start|stop|restart|create|h(?:elp)?|v(?:ersion)?|console|status)/) }
257
- if command.nil?
258
- command = ""
259
- else
260
- ARGV.delete(command)
261
- end
61
+ ENV['IRBRC'] = ".irbrc" if File.exists? ".irbrc"
62
+ Ramaze.start! :run_loose => true
63
+ IRB.start
64
+ Ramaze.shutdown
65
+ end
66
+
67
+ daemonize = Ramaze::Global.daemonize
262
68
 
263
- case command
264
- when /^(?:--?)?status$/
265
- status(command)
266
- when /^(?:--?)?restart$/
267
- stop(command)
268
- start
269
- when /^(?:--?)?start$/
270
- start
271
- when /^(?:--?)?create$/
272
- create(command)
273
- when /^(?:--?)?stop$/
274
- if stop(command)
275
- puts "Ramazement has ended, go in peace."
276
- $stdout.flush
69
+ unless daemonize.empty?
70
+ require 'ramaze/tool/daemonize'
71
+ Ramaze::daemonize(runner, daemonize)
277
72
  else
278
- puts "Ramaze failed to stop (or was not running)"
73
+ Ramaze.trait[:started] = true
74
+ require runner
75
+ Ramaze.start!
279
76
  end
280
- when /^(?:--?)?console$/
281
- require "ramaze"
282
- require "irb"
283
- require "irb/completion"
284
- Ramaze.options.started = true
285
- require "start"
286
- IRB.start
287
- puts "Ramazement has ended, go in peace."
288
- when /^(?:--?)?h(elp)?$/
289
- puts usage
290
- when /^(?:--?)?v(ersion)?$/
291
- include_ramaze
292
- puts Ramaze::VERSION
293
- exit
294
- when /^$/
295
- puts "Must supply a valid command"
296
- puts usage
297
- exit 1
298
77
  else
299
- puts "#{command} not implemented"
300
- puts usage
301
- exit 1
78
+ Ramaze::Global.merge!(ARGV, &additions)
79
+ puts Ramaze::Global.option_parser(&additions)
302
80
  end
303
-
@@ -3,7 +3,7 @@
3
3
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4
4
  <head>
5
5
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
- <meta name="generator" content="AsciiDoc 8.4.2" />
6
+ <meta name="generator" content="AsciiDoc 8.4.1" />
7
7
  <title>The official Ramaze Todo-list tutorial</title>
8
8
  <style type="text/css">
9
9
  /* Debug borders */
@@ -448,12 +448,6 @@ either on the <a href="http://ramazetrac.purepistos.org/">Bug tracker</a>, or ju
448
448
  drop by on IRC on <tt>irc.freenode.org</tt> in the channel <tt>#ramaze</tt>.</p></div>
449
449
  <div class="paragraph"><p>If you have trouble with some of the terms used in this tutorial you can
450
450
  consult the <a href="#glossary">Glossary</a> at the end of this document.</p></div>
451
- <div class="paragraph"><p>We are also working on a book that describes Ramaze in more depth, called
452
- <em>Journey to Ramaze</em>, it is still very much work in progress, but some of the
453
- contents might interest you.</p></div>
454
- <div class="paragraph"><p>The repository for the book is at <a href="http://github.com/manveru/ramaze-book">http://github.com/manveru/ramaze-book</a>.
455
- Every once in a while, updates for the book will be available in HTML and PDF
456
- form at <a href="http://book.ramaze.net">http://book.ramaze.net</a>.</p></div>
457
451
  </div>
458
452
  <h2 id="_first_step_create">First Step, Create</h2>
459
453
  <div class="sectionbody">
@@ -527,7 +521,7 @@ Ramaze<span style="color: #990000">.</span>start</tt></pre></div></div>
527
521
  <pre><tt>delta ~/tmp/tutorial % ruby start.rb
528
522
  D [2009-03-30 14:15:01 $2124] DEBUG | : Using webrick
529
523
  I [2009-03-30 14:15:01 $2124] INFO | : WEBrick 1.3.1
530
- I [2009-03-30 14:15:01 $2124] INFO | : ruby 1.9.2 (2009-03-02) [i686-linux]
524
+ I [2009-03-30 14:15:01 $2124] INFO | : ruby 1.8.7 (2008-08-11) [i686-linux]
531
525
  D [2009-03-30 14:15:01 $2124] DEBUG | : TCPServer.new(0.0.0.0, 7000)
532
526
  D [2009-03-30 14:15:01 $2124] DEBUG | : Rack::Handler::WEBrick is mounted on /.
533
527
  I [2009-03-30 14:15:01 $2124] INFO | : WEBrick::HTTPServer#start: pid=2124 port=7000</tt></pre>
@@ -558,7 +552,8 @@ you tremendously when it comes to writing your own applications.</p></div>
558
552
  This requires the <a href="http://rubyforge.org/projects/sqlite-ruby">sqlite-ruby</a>
559
553
  bindings.</p></div>
560
554
  <div class="paragraph"><p>You can try to <tt>gem install sqlite</tt>, which will complain if your system doesn&#8217;t
561
- provide bindings, in which case I have to refer you to <a href="http://sqlite.org">http://sqlite.org</a>.</p></div>
555
+ provide bindings, in which case I have to refer you to
556
+ TODO <a href="http://sqlite.rubyforge.org">http://sqlite.rubyforge.org</a></p></div>
562
557
  <div class="paragraph"><p>In order to use Sequel we also need a database connection.</p></div>
563
558
  <div class="paragraph"><p>So we create a new file at <em>model/init.rb</em> with following content:</p></div>
564
559
  <div class="listingblock">
@@ -568,11 +563,7 @@ http://www.lorenzobettini.it
568
563
  http://www.gnu.org/software/src-highlite -->
569
564
  <pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'sequel'</span>
570
565
 
571
- Sequel<span style="color: #990000">::</span>Model<span style="color: #990000">.</span>plugin<span style="color: #990000">(:</span>schema<span style="color: #990000">)</span>
572
-
573
566
  DB <span style="color: #990000">=</span> Sequel<span style="color: #990000">.</span>sqlite<span style="color: #990000">(</span><span style="color: #FF0000">'todolist.db'</span><span style="color: #990000">)</span></tt></pre></div></div>
574
- <div class="paragraph"><p>The <tt>:schema</tt> plugin is required since Sequel 3.0, if you run a version prior
575
- to 2.12 you may remove this line if it gives you any problems.</p></div>
576
567
  <div class="paragraph"><p>Next we edit <em>start.rb</em>, remove the <tt>Hello</tt> class, and add a require for the
577
568
  file, <em>start.rb</em> should look like this now:</p></div>
578
569
  <div class="listingblock">
@@ -620,8 +611,6 @@ http://www.lorenzobettini.it
620
611
  http://www.gnu.org/software/src-highlite -->
621
612
  <pre><tt><span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'sequel'</span>
622
613
 
623
- Sequel<span style="color: #990000">::</span>Model<span style="color: #990000">.</span>plugin<span style="color: #990000">(:</span>schema<span style="color: #990000">)</span>
624
-
625
614
  DB <span style="color: #990000">=</span> Sequel<span style="color: #990000">.</span>sqlite<span style="color: #990000">(</span><span style="color: #FF0000">'todolist.db'</span><span style="color: #990000">)</span>
626
615
 
627
616
  <span style="font-weight: bold"><span style="color: #000080">require</span></span> <span style="color: #FF0000">'model/task'</span></tt></pre></div></div>
@@ -1266,73 +1255,6 @@ http://www.gnu.org/software/src-highlite -->
1266
1255
  <div class="paragraph"><p>Voilà, you now have acquired the Certificate of Ramazeness and all your friends
1267
1256
  and enemies envy you.</p></div>
1268
1257
  </div>
1269
- <h2 id="_twelfth_step_configuring_configurable_configurability">Twelfth Step, configuring configurable configurability</h2>
1270
- <div class="sectionbody">
1271
- <div class="paragraph"><p>To round up this tutorial a bit, let&#8217;s introduce you to configuration in Ramaze.
1272
- There are a number of ways to configure Ramaze, but here we&#8217;ll just see the
1273
- most common ones with some options you&#8217;ll most likely want to change.</p></div>
1274
- <div class="paragraph"><p>First of all, you have been running your ramaze application always on the same
1275
- port, <tt>7000</tt>, which prevents you from starting more than one instance or other
1276
- applications.</p></div>
1277
- <div class="paragraph"><p>To change the port, you can, for example:</p></div>
1278
- <div class="listingblock">
1279
- <div class="content"><!-- Generator: GNU source-highlight 2.11.1
1280
- by Lorenzo Bettini
1281
- http://www.lorenzobettini.it
1282
- http://www.gnu.org/software/src-highlite -->
1283
- <pre><tt>Ramaze<span style="color: #990000">.</span>options<span style="color: #990000">.</span>adapter<span style="color: #990000">.</span>port <span style="color: #990000">=</span> <span style="color: #993399">80</span></tt></pre></div></div>
1284
- <div class="admonitionblock">
1285
- <table><tr>
1286
- <td class="icon">
1287
- <div class="title">Note</div>
1288
- </td>
1289
- <td class="content">Running a server on a port below 1024 will require root privileges and is
1290
- generally not advised for applications that don&#8217;t drop their privileges
1291
- after establishing a connection.
1292
- Please have a look at <a href="http://wiki.ramaze.net/Deployment">http://wiki.ramaze.net/Deployment</a> for better ways
1293
- to deploy your site using a reverse proxy like apache, lighttpd, or
1294
- nginx.</td>
1295
- </tr></table>
1296
- </div>
1297
- <div class="paragraph"><p>OK, a different port is fine, but how about some speed-boost? For this we will
1298
- need a faster server like <a href="http://mongrel.rubyforge.org">Mongrel</a> or
1299
- <a href="http://thin.rubyforge.org">Thin</a>.</p></div>
1300
- <div class="paragraph"><p>You can install either one via:</p></div>
1301
- <div class="listingblock">
1302
- <div class="content">
1303
- <pre><tt>gem install thin
1304
- gem install mongrel</tt></pre>
1305
- </div></div>
1306
- <div class="paragraph"><p>Now to the configuration:</p></div>
1307
- <div class="listingblock">
1308
- <div class="content"><!-- Generator: GNU source-highlight 2.11.1
1309
- by Lorenzo Bettini
1310
- http://www.lorenzobettini.it
1311
- http://www.gnu.org/software/src-highlite -->
1312
- <pre><tt><span style="font-style: italic"><span style="color: #9A1900"># The default is WEBrick</span></span>
1313
- Ramaze<span style="color: #990000">.</span>options<span style="color: #990000">.</span>adapter<span style="color: #990000">.</span>adapter <span style="color: #990000">=</span> <span style="color: #990000">:</span>webrick
1314
-
1315
- <span style="font-style: italic"><span style="color: #9A1900"># How about using Mongrel instead?</span></span>
1316
- Ramaze<span style="color: #990000">.</span>options<span style="color: #990000">.</span>adapter<span style="color: #990000">.</span>adapter <span style="color: #990000">=</span> <span style="color: #990000">:</span>mongrel
1317
-
1318
- <span style="font-style: italic"><span style="color: #9A1900"># Or maybe Thin?</span></span>
1319
- Ramaze<span style="color: #990000">.</span>options<span style="color: #990000">.</span>adapter<span style="color: #990000">.</span>adapter <span style="color: #990000">=</span> <span style="color: #990000">:</span>thin</tt></pre></div></div>
1320
- <div class="paragraph"><p>For the full performance, switch Ramaze into <tt>:live</tt> mode:</p></div>
1321
- <div class="listingblock">
1322
- <div class="content"><!-- Generator: GNU source-highlight 2.11.1
1323
- by Lorenzo Bettini
1324
- http://www.lorenzobettini.it
1325
- http://www.gnu.org/software/src-highlite -->
1326
- <pre><tt><span style="font-style: italic"><span style="color: #9A1900"># The default is :dev</span></span>
1327
- Ramaze<span style="color: #990000">.</span>options<span style="color: #990000">.</span>mode <span style="color: #990000">=</span> <span style="color: #990000">:</span>live
1328
-
1329
- <span style="font-style: italic"><span style="color: #9A1900"># And here comes :live</span></span>
1330
- Ramaze<span style="color: #990000">.</span>options<span style="color: #990000">.</span>mode <span style="color: #990000">=</span> <span style="color: #990000">:</span>live</tt></pre></div></div>
1331
- <div class="paragraph"><p>The major differences between <tt>:dev</tt> and <tt>:live</tt> are that in <tt>:live</tt> mode your
1332
- code won&#8217;t be automatically reloaded if it has changed and we don&#8217;t run every
1333
- request through <tt>Rack::Lint</tt>, which helps you to stay within the
1334
- request/response specifications required by Rack.</p></div>
1335
- </div>
1336
1258
  <h2 id="glossary">Glossary</h2>
1337
1259
  <div class="sectionbody">
1338
1260
  <div class="dlist glossary"><dl>
@@ -1408,7 +1330,7 @@ RSI
1408
1330
  <div id="footer">
1409
1331
  <div id="footer-text">
1410
1332
  Version 2.0<br />
1411
- Last updated 2009-04-07 19:08:12 JST
1333
+ Last updated 2009-03-30 20:29:25 JST
1412
1334
  </div>
1413
1335
  </div>
1414
1336
  </body>
@@ -32,15 +32,6 @@ drop by on IRC on `irc.freenode.org` in the channel `#ramaze`.
32
32
  If you have trouble with some of the terms used in this tutorial you can
33
33
  consult the <<glossary, Glossary>> at the end of this document.
34
34
 
35
- We are also working on a book that describes Ramaze in more depth, called
36
- 'Journey to Ramaze', it is still very much work in progress, but some of the
37
- contents might interest you.
38
-
39
- The repository for the book is at http://github.com/manveru/ramaze-book.
40
- Every once in a while, updates for the book will be available in HTML and PDF
41
- form at http://book.ramaze.net.
42
-
43
-
44
35
  == First Step, Create
45
36
 
46
37
  The last version of this tutorial assumed a generator to produce a skeleton in
@@ -96,7 +87,7 @@ tradition, we create a file at the root of your application directory called
96
87
  require 'rubygems'
97
88
  require 'ramaze'
98
89
 
99
- class MainController < Ramaze::Controller
90
+ class Hello < Ramaze::Controller
100
91
  def index
101
92
  "Hello, World!"
102
93
  end
@@ -111,7 +102,7 @@ Now we run it:
111
102
  delta ~/tmp/tutorial % ruby start.rb
112
103
  D [2009-03-30 14:15:01 $2124] DEBUG | : Using webrick
113
104
  I [2009-03-30 14:15:01 $2124] INFO | : WEBrick 1.3.1
114
- I [2009-03-30 14:15:01 $2124] INFO | : ruby 1.9.2 (2009-03-02) [i686-linux]
105
+ I [2009-03-30 14:15:01 $2124] INFO | : ruby 1.8.7 (2008-08-11) [i686-linux]
115
106
  D [2009-03-30 14:15:01 $2124] DEBUG | : TCPServer.new(0.0.0.0, 7000)
116
107
  D [2009-03-30 14:15:01 $2124] DEBUG | : Rack::Handler::WEBrick is mounted on /.
117
108
  I [2009-03-30 14:15:01 $2124] INFO | : WEBrick::HTTPServer#start: pid=2124 port=7000
@@ -150,7 +141,8 @@ This requires the http://rubyforge.org/projects/sqlite-ruby[sqlite-ruby]
150
141
  bindings.
151
142
 
152
143
  You can try to `gem install sqlite`, which will complain if your system doesn't
153
- provide bindings, in which case I have to refer you to http://sqlite.org.
144
+ provide bindings, in which case I have to refer you to
145
+ TODO http://sqlite.rubyforge.org
154
146
 
155
147
  In order to use Sequel we also need a database connection.
156
148
 
@@ -160,14 +152,9 @@ So we create a new file at 'model/init.rb' with following content:
160
152
  --------------------------------------------------------------------------------
161
153
  require 'sequel'
162
154
 
163
- Sequel::Model.plugin(:schema)
164
-
165
155
  DB = Sequel.sqlite('todolist.db')
166
156
  --------------------------------------------------------------------------------
167
157
 
168
- The `:schema` plugin is required since Sequel 3.0, if you run a version prior
169
- to 2.12 you may remove this line if it gives you any problems.
170
-
171
158
  Next we edit 'start.rb', remove the `Hello` class, and add a require for the
172
159
  file, 'start.rb' should look like this now:
173
160
 
@@ -215,8 +202,6 @@ Finally, add a line to your 'model/init.rb' that requires 'model/task.rb':
215
202
  --------------------------------------------------------------------------------
216
203
  require 'sequel'
217
204
 
218
- Sequel::Model.plugin(:schema)
219
-
220
205
  DB = Sequel.sqlite('todolist.db')
221
206
 
222
207
  require 'model/task'
@@ -847,72 +832,35 @@ What we do cover is adding it to your application, or the `<head>` in
847
832
  Voilà, you now have acquired the Certificate of Ramazeness and all your friends
848
833
  and enemies envy you.
849
834
 
850
-
851
- == Twelfth Step, configuring configurable configurability
852
-
853
- To round up this tutorial a bit, let's introduce you to configuration in Ramaze.
854
- There are a number of ways to configure Ramaze, but here we'll just see the
855
- most common ones with some options you'll most likely want to change.
856
-
857
- First of all, you have been running your ramaze application always on the same
858
- port, `7000`, which prevents you from starting more than one instance or other
859
- applications.
860
-
861
- To change the port, you can, for example:
862
-
863
- [source,ruby]
864
- --------------------------------------------------------------------------------
865
- Ramaze.options.adapter.port = 80
866
- --------------------------------------------------------------------------------
867
-
868
- NOTE: Running a server on a port below 1024 will require root privileges and is
869
- generally not advised for applications that don't drop their privileges
870
- after establishing a connection.
871
- Please have a look at http://wiki.ramaze.net/Deployment for better ways
872
- to deploy your site using a reverse proxy like apache, lighttpd, or
873
- nginx.
874
-
875
- OK, a different port is fine, but how about some speed-boost? For this we will
876
- need a faster server like http://mongrel.rubyforge.org[Mongrel] or
877
- http://thin.rubyforge.org[Thin].
878
-
879
- You can install either one via:
880
-
881
- --------------------------------------------------------------------------------
882
- gem install thin
883
- gem install mongrel
884
- --------------------------------------------------------------------------------
885
-
886
- Now to the configuration:
887
-
888
- [source,ruby]
889
- --------------------------------------------------------------------------------
890
- # The default is WEBrick
891
- Ramaze.options.adapter.adapter = :webrick
892
-
893
- # How about using Mongrel instead?
894
- Ramaze.options.adapter.adapter = :mongrel
895
-
896
- # Or maybe Thin?
897
- Ramaze.options.adapter.adapter = :thin
898
- --------------------------------------------------------------------------------
899
-
900
- For the full performance, switch Ramaze into `:live` mode:
901
-
902
- [source,ruby]
903
- --------------------------------------------------------------------------------
904
- # The default is :dev
905
- Ramaze.options.mode = :live
906
-
907
- # And here comes :live
908
- Ramaze.options.mode = :live
909
- --------------------------------------------------------------------------------
910
-
911
- The major differences between `:dev` and `:live` are that in `:live` mode your
912
- code won't be automatically reloaded if it has changed and we don't run every
913
- request through `Rack::Lint`, which helps you to stay within the
914
- request/response specifications required by Rack.
915
-
835
+ ////
836
+ That's just some experimental stuff, uncomment and create an 'image' folder to
837
+ use it.
838
+
839
+ [graphviz,"image/relations.png","dot"]
840
+ ---------------------------------------------------------------------
841
+ digraph relations {
842
+ "start.rb" -> "controller/task.rb";
843
+ "start.rb" -> "model/init.rb";
844
+ "model/init.rb" -> "model/task.rb";
845
+ "controller/task.rb" -> "layout/default.xhtml";
846
+ "controller/task.rb" -> "view/index.xhtml";
847
+ "controller/task.rb" -> "view/done.xhtml";
848
+ "layout/default.xhtml" -> "public/css/screen.css";
849
+
850
+ "Tasks Controller" -> "create action";
851
+ "Tasks Controller" -> "index action";
852
+ "Tasks Controller" -> "open action";
853
+ "Tasks Controller" -> "done action";
854
+ "Tasks Controller" -> "close action";
855
+ "Tasks Controller" -> "delete action";
856
+
857
+ "done action" -> "Task.filter(:done => true)";
858
+ "index action" -> "Task.filter(:done => false)";
859
+ }
860
+ ---------------------------------------------------------------------
861
+
862
+ image:image/relations.png[Relations of parts of the application]
863
+ ////
916
864
 
917
865
  [[glossary]]
918
866
  == Glossary