aboutsummaryrefslogtreecommitdiff
path: root/html.rb
diff options
context:
space:
mode:
authorBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-19 23:39:54 +0100
committerBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-19 23:39:54 +0100
commit7effadace31c5c9efee2708e28acc4359b534b25 (patch)
tree85a859a8deeb616f88b83fed18f35702b6b0026e /html.rb
parent0e8d1d9d28d127704897bb9fb4ea06105a1d0f84 (diff)
better code structure
Diffstat (limited to 'html.rb')
-rw-r--r--html.rb59
1 files changed, 43 insertions, 16 deletions
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>