aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--charset.rb8
-rw-r--r--html.rb59
-rwxr-xr-xparticipate.rb27
3 files changed, 58 insertions, 36 deletions
diff --git a/charset.rb b/charset.rb
index ad6c836..d713759 100644
--- a/charset.rb
+++ b/charset.rb
@@ -4,10 +4,8 @@
# see License #
################################
-utfcookie = CGI::Cookie.new("utf", "true")
-utfcookie.path = "/"
if ($cgi.include?("utf") || $cgi.cookies["utf"][0]) && !$cgi.include?("ascii")
- utfcookie.expires = Time.now+1*60*60*24*365
+ expiretime = Time.now+1*60*60*24*365
UTFASCII = "<a href='?ascii' style='text-decoration:none'>Change Charset to plain ASCII</a>"
YES = CGI.escapeHTML('✔')
@@ -23,7 +21,7 @@ if ($cgi.include?("utf") || $cgi.cookies["utf"][0]) && !$cgi.include?("ascii")
EDIT = CGI.escapeHTML("✍")
DELETE = CGI.escapeHTML("⌧")
else
- utfcookie.expires = Time.now-1*60*60*24*36
+ expiretime = Time.now-1*60*60*24*36
UTFASCII = "<a href='?utf' style='text-decoration:none'>If you see all these characters: #{CGI.escapeHTML('✔✘?–↞←→↠✍⌧')} you can safely change the charset to UTF-8</a>"
YES = CGI.escapeHTML('OK')
@@ -39,4 +37,4 @@ else
EDIT = CGI.escapeHTML("edit")
DELETE = CGI.escapeHTML("delete")
end
-$html.header["cookie"] = utfcookie
+$html.add_cookie("utf","true","/",expiretime)
diff --git a/html.rb b/html.rb
index 93739ba..b40cca6 100644
--- a/html.rb
+++ b/html.rb
@@ -1,37 +1,40 @@
+################################
+# Author: Benjamin Kellermann #
+# License: CC-by-sa 3.0 #
+# see License #
+################################
class HTML
- attr_accessor :title, :htmlout, :header
- def initialize
+ attr_accessor :body, :header
+ def initialize(title)
+ @title = title
@header = {}
@header["type"] = "text/html"
# @header["type"] = "application/xhtml+xml"
@header["charset"] = "utf-8"
- @htmlout = <<HEAD
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-HEAD
+ @body = ""
@css = {}
@atom = []
end
- def add_head(title)
- @htmlout += <<HEAD
+ def head
+ ret = <<HEAD
<head>
<meta http-equiv="Content-Type" content="#{@header["type"]}; charset=#{@header["charset"]}" />
<meta http-equiv="Content-Style-Type" content="text/css" />
- <title>#{title}</title>
+ <title>#{@title}</title>
HEAD
@css.each{|title,href|
- @htmlout += "<link rel='stylesheet' type='text/css' href='#{href}' title='#{title}'/>"
- @htmlout += "<link rel='stylesheet' type='text/css' href='#{href}' title='print' media='print' />" if title == "print"
+ ret += "<link rel='stylesheet' type='text/css' href='#{href}' title='#{title}'/>"
+ ret += "<link rel='stylesheet' type='text/css' href='#{href}' title='print' media='print' />" if title == "print"
}
@atom.each{|href|
- @htmlout += "<link rel='alternate' type='application/atom+xml' href='#{href}' />"
+ ret += "<link rel='alternate' type='application/atom+xml' href='#{href}' />"
}
- @htmlout += "</head>"
+ ret += "</head>"
+ ret
end
def add_css(href, title = "default")
@css[title] ||= []
@@ -40,8 +43,32 @@ HEAD
def add_atom(href)
@atom << href
end
- def add_tabs
- @htmlout += <<HEAD
+ def add_cookie(key,value,path,expiretime)
+ c = CGI::Cookie.new(key, value)
+ c.path = path
+ c.expires = expiretime
+ @header["cookie"] = c
+ end
+ def << (bodycontent)
+ @body += bodycontent
+ end
+ def out(cgi)
+ cgi.out(@header){
+ <<HEAD
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+#{head}
+#{@body}
+</html>
+HEAD
+ }
+ end
+end
+
+module Dudle
+ def Dudle.tabs
+ return <<HEAD
<div id='tabs'>
<ul>
<li id='active_tab' >&nbsp;poll&nbsp;</li>
diff --git a/participate.rb b/participate.rb
index 7f8dce2..d134eb2 100755
--- a/participate.rb
+++ b/participate.rb
@@ -14,13 +14,10 @@ require "cgi"
$cgi = CGI.new
-
olddir = File.expand_path(".")
Dir.chdir("..")
require "html"
-$html = HTML.new
require "poll"
-load "charset.rb"
load "config.rb"
Dir.chdir(olddir)
@@ -48,23 +45,26 @@ else
table.add_comment($cgi["commentname"],$cgi["comment"]) if $cgi["comment"] != ""
table.delete_comment($cgi["delete_comment"].to_i) if $cgi.include?("delete_comment")
end
+$html = HTML.new("dudle - #{table.name}")
+$html.header["Cache-Control"] = "no-cache"
+load "../charset.rb"
$html.add_css("../dudle.css")
$html.add_css("../print.css","print")
$html.add_atom("atom.cgi") if File.exists?("../atom.rb")
-$html.add_head("dudle - #{table.name}")
-$html.htmlout += "<body>"
-$html.add_tabs
+$html << "<body>"
+
+$html << Dudle::tabs
-$html.htmlout += <<HEAD
+$html << <<HEAD
<div id='main'>
HEAD
# TABLE
if VCS.revno == 1
- $html.htmlout += <<HINT
+ $html << <<HINT
<h1>#{table.name}</h1>
<pre id='configwarning'>
.
@@ -85,7 +85,7 @@ if VCS.revno == 1
</pre>
HINT
else
- $html.htmlout += <<TABLE
+ $html << <<TABLE
<p id='history'>history:#{table.history_to_html}</p>
<h1>#{table.name}</h1>
<div id='polltable'>
@@ -95,13 +95,10 @@ else
</div>
TABLE
- $html.htmlout += table.comment_to_html
+ $html << table.comment_to_html
end
-$html.htmlout += "</div></body>"
+$html << "</div></body>"
-$html.htmlout += "</html>"
-
-$html.header["Cache-Control"] = "no-cache"
-$cgi.out($html.header){$html.htmlout}
+$html.out($cgi)
end