public
Rubygem
Description: A Ruby wrapper around the Extended Environments Markup Language
Homepage: http://github.com/Floppy/eeml-ruby
Clone URL: git://github.com/Floppy/eeml-ruby.git
eeml-ruby / examples / simple_server.rb
100755 31 lines (23 sloc) 0.698 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/local/bin/ruby
 
dir = File.dirname(__FILE__) + '/../lib'
$LOAD_PATH << dir unless $LOAD_PATH.include?(dir)
 
require 'webrick'
require 'eeml'
 
# Create an environment object
$environment = EEML::Environment.new
 
# Set dummy data in environment object
$environment << EEML::Data.new(42)
 
# Create WEBrick server
s = WEBrick::HTTPServer.new( :Port => 50000 )
 
# Create a simple webrick servlet for index.eeml
class EEMLServlet < WEBrick::HTTPServlet::AbstractServlet
  def do_GET(request, response)
    response.status = 200
    response['Content-Type'] = "text/xml"
    response.body = $environment.to_eeml
  end
end
s.mount("/index.eeml", EEMLServlet)
 
# Go
trap("INT"){ s.shutdown }
s.start