Ukažme si nyní nejednodušší aplikaci. Jedná so o obligátní program „Hello“.
Příklad 51.20. Jednoduchá aplikace
#!/usr/bin/env ruby
# $Id: hello1.rb,v 1.2 2003/12/08 18:40:07 radek Exp $
# $Source: /home/radek/cvs/ruby-book/example/net/web/borges/hello1.rb,v $
# Simple Hello1 application
# Copyright (c) 2003 Radek Hnilica
# License: See Ruby license or GPL
require 'Borges'
module Hello
class Page < Borges::Component
def render_content_on(r)
r.heading "Hello, world"
end
register_application 'hello1'
end
end
if $0 == __FILE__ then
require 'Borges/WEBrick'
Borges::WEBrickServlet.start
end
### Keep this comment at the end of the file
#Local variables:
#ruby-indent-level:2
#End:
Aplikaci spustíme
$ ./hello1.rb
[2003-12-08 13:41:13] INFO WEBrick 1.3.1
[2003-12-08 13:41:13] INFO ruby 1.8.1 (2003-10-31) [i686-linux]
[2003-12-08 13:41:18] INFO WEBrick::HTTPServer#start: pid=9678 port=7000A na její stránku podíváme
$ galeon -n localhost:7000/borges/hello1Aplikace funguje a nyní si ji upravíme pro Apache. Vytvoříme stránku
Příklad 51.21. Stránka pro Apache
#!/usr/bin/env ruby
# $Id: hello1.rbx,v 1.1 2005/10/04 08:52:07 radek Exp $
# $Source: /home/radek/cvs/ruby-book/example/net/web/borges/hello1.rbx,v $
require 'Borges/ApacheDRbClient'
DRb.start_service
Borges::ApacheDRbClient.handle_request('druby://127.0.0.1:7001')
Příklad 51.22. Server aplikace hello1
#!/usr/bin/env ruby
# $Id: hello1.srv,v 1.1 2005/10/04 08:52:07 radek Exp $
# $Source: /home/radek/cvs/ruby-book/example/net/web/borges/hello1.srv,v $
require 'hello1.rb'
require 'Borges/ApacheDRbServer'
#Borges::register_application("borges/hello.rbx", Hello)
Borges::ApacheDRbServer.start('druby://127.0.0.1:7001')
Borges::ApacheDRbServer.install_INT_handler
puts "Borges DRb Server listening on #{DRb.uri}"
puts "Press Ctrl-c to quit"
DRb.thread.join
Metoda register_application použitá k registraci aplikace je definována v třídě Třída Borgess::Controller.
FIXME:
