diff options
Diffstat (limited to 'html.rb')
-rw-r--r-- | html.rb | 59 |
1 files changed, 43 insertions, 16 deletions
@@ -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' > poll </li> |