############################################################################ # Copyright 2009,2010 Benjamin Kellermann # # # # This file is part of dudle. # # # # Dudle is free software: you can redistribute it and/or modify it under # # the terms of the GNU Affero General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # Dudle is distributed in the hope that it will be useful, but WITHOUT ANY # # WARRANTY; without even the implied warranty of MERCHANTABILITY or # # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public # # License for more details. # # # # You should have received a copy of the GNU Affero General Public License # # along with dudle. If not, see . # ############################################################################ class HTML attr_accessor :body, :header def initialize(title) @title = title @header = {} @header["type"] = "text/html" # @header["type"] = "application/xhtml+xml" @header["charset"] = "utf-8" @body = "" @css = [] @atom = [] end def head ret = < #{@title} HEAD @css = [@css[0]] + @css[1..-1].sort unless @css.empty? @css.each{|title,href| ret += "\n" ret += "\n" if title == "print" } @atom.each{|href| ret += "\n" } ret += "" ret end def add_css(href, title, default = false) if default @css.unshift([title,href]) else @css << [title,href] end end def add_atom(href) @atom << href end def add_cookie(key,value,path,expiretime) c = CGI::Cookie.new(key, value) c.path = path c.expires = expiretime @header["cookie"] ||= [] @header["cookie"] << c end def << (bodycontent) @body += bodycontent.chomp + "\n" end def out(cgi) cgi.out(@header){ < #{head} #{@body} HEAD } end end