-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_cgi.rb
48 lines (39 loc) · 913 Bytes
/
simple_cgi.rb
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env ruby
# simple_cgi.rb
require 'cgi'
class Simple_CGI
EMPTY_STRING = ''
TITLE = 'A simple CGI script'
def display()
cgi = CGI.new('html4')
output = cgi.html do
cgi.head do
cgi.title { TITLE }
end +
cgi.body do
cgi.h1 { TITLE } +
show_def_list(cgi)
end
end
cgi.out { output.gsub('><', ">\n<") }
end
private
def get_items_hash()
{
'script' => ENV['SCRIPT_NAME'],
'server' => ENV['SERVER_NAME'] || %x{hostname} || EMPTY_STRING,
'software' => ENV['SERVER_SOFTWARE'],
'time' => Time.now,
}
end
def show_def_list(cgi)
cgi.dl do
items = get_items_hash.merge(cgi.params)
items.keys.sort.map do |term|
definition = items[term]
"<dt>#{term}</dt><dd>#{definition}</dd>\n"
end.join( EMPTY_STRING )
end
end
end
Simple_CGI.new.display()