From 7effadace31c5c9efee2708e28acc4359b534b25 Mon Sep 17 00:00:00 2001 From: Benjamin Kellermann Date: Thu, 19 Nov 2009 23:39:54 +0100 Subject: better code structure --- charset.rb | 8 +++----- html.rb | 59 ++++++++++++++++++++++++++++++++++++++++++---------------- participate.rb | 27 ++++++++++++--------------- 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 = "Change Charset to plain ASCII" 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 = "If you see all these characters: #{CGI.escapeHTML('✔✘?–↞←→↠✍⌧')} you can safely change the charset to UTF-8" 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 + @body = "" @css = {} @atom = [] end - def add_head(title) - @htmlout += < - #{title} + #{@title} HEAD @css.each{|title,href| - @htmlout += "" - @htmlout += "" if title == "print" + ret += "" + ret += "" if title == "print" } @atom.each{|href| - @htmlout += "" + ret += "" } - @htmlout += "" + ret += "" + 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} +#{@body} + +HEAD + } + end +end + +module Dudle + def Dudle.tabs + return <