From 54386017ceacacb2a6990a29bffc7f93982572e4 Mon Sep 17 00:00:00 2001 From: Benjamin Kellermann Date: Thu, 26 Nov 2009 00:15:10 +0100 Subject: heavy code restructuring, moved common code to dudle.rb --- access_control.rb | 39 +++++----------------- charset.rb | 1 - customize.rb | 46 ++++++++++--------------- delete_poll.rb | 52 +++++++---------------------- dudle.rb | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ edit_columns.rb | 60 ++++++++------------------------- help.rb | 34 ++++--------------- history.rb | 50 ++++++--------------------- html.rb | 29 ---------------- invite_participants.rb | 36 ++++---------------- participate.rb | 52 +++++++---------------------- timepollhead.rb | 9 +++++ 12 files changed, 189 insertions(+), 310 deletions(-) create mode 100644 dudle.rb diff --git a/access_control.rb b/access_control.rb index 6080452..a40ad43 100755 --- a/access_control.rb +++ b/access_control.rb @@ -19,22 +19,11 @@ # along with dudle. If not, see . # ############################################################################ -require "cgi" - if __FILE__ == $0 -$cgi = CGI.new -olddir = File.expand_path(".") -Dir.chdir("..") -load "html.rb" -load "config.rb" -require "poll" -require "yaml" -Dir.chdir(olddir) +load "../dudle.rb" -POLL = YAML::load_file("data.yaml").name -$html = HTML.new("dudle - #{POLL} - Help") -$html.header["Cache-Control"] = "no-cache" +$d = Dudle.new("Access Control") acusers = {} @@ -66,9 +55,9 @@ HTACCESS } VCS.commit("Access Control changed") unless acusers.empty? - $html.header["status"] = "REDIRECT" - $html.header["Cache-Control"] = "no-cache" - $html.header["Location"] = "access_control.cgi" + $d.html.header["status"] = "REDIRECT" + $d.html.header["Cache-Control"] = "no-cache" + $d.html.header["Location"] = "access_control.cgi" end end def add_to_htdigest(user,password) @@ -173,19 +162,10 @@ if $cgi.include?("ac_user") end end -unless $html.header["status"] == "REDIRECT" - -load "../charset.rb" -$html.add_css("../dudle.css") +unless $d.html.header["status"] == "REDIRECT" -$html << "" -$html << Dudle::tabs("Access Control") -$html << < -

#{POLL}

-

Change Access Control Settings

-HEAD +$d.html << "

Change Access Control Settings

" if acusers.empty? && $cgi["ac_activate"] != "Activate" @@ -216,7 +196,7 @@ else end -$html << < @@ -239,8 +219,7 @@ $html << <" end -$html.out($cgi) +$d.out($cgi) end diff --git a/charset.rb b/charset.rb index b305eac..237a8c1 100644 --- a/charset.rb +++ b/charset.rb @@ -64,4 +64,3 @@ else end UTFCHARS = CGI.escapeHTML("✔✘↞←→↠✍⌧•▾▴") -$html.add_cookie("utf","true","/",Time.now + (1*60*60*24*365 * (USEUTF ? 1 : -1 ))) diff --git a/customize.rb b/customize.rb index 5300b1c..8b0aeee 100755 --- a/customize.rb +++ b/customize.rb @@ -19,24 +19,16 @@ # along with dudle. If not, see . # ############################################################################ -require "cgi" if __FILE__ == $0 -$cgi = CGI.new -load "../html.rb" -$html = HTML.new("dudle - Customize") -load "../charset.rb" +load "../dudle.rb" -$html.header["Cache-Control"] = "no-cache" +$d = Dudle.new("Customize") -$html.add_css("../dudle.css") -$html << < -#{Dudle::tabs("Customize")} -
-

Customize Personal Settings

+$d << <Customize Personal Settings You need cookies enabled in order to personalize your settings. END @@ -65,9 +57,10 @@ end a = [["Use normal strings","ascii"], ["Use special characters (#{UTFCHARS})","utf", "Use this options if you see the characters in the parenthesis."]] -$html << < -

Charset

+

Charset

#{choosetable("Charset settings",a,USEUTF ? "utf" : "ascii")}
CHARSET @@ -80,10 +73,10 @@ a = [["default","css=dudle.css"], css = $cgi.cookies["css"][0] css = $cgi["css"] if $cgi.include?("css") css ||= "dudle.css" -$html.add_cookie("css",css,"/",Time.now + (1*60*60*24*365 * (css == "dudle.css" ? -1 : 1 ))) -$html << < -

Stylesheet

+

Stylesheet

#{choosetable("Stylesheet settings",a,"css=#{css}")} CSS @@ -91,15 +84,15 @@ CSS username = $cgi.cookies["username"][0] if $cgi.include?("delete_username") - $html.add_cookie("username","","/",Time.now - 1*60*60*24*365) + $d.html.add_cookie("username","","/",Time.now - 1*60*60*24*365) username = nil elsif $cgi.include?("username") username = $cgi["username"] - $html.add_cookie("username",username,"/",Time.now + 1*60*60*24*365) + $d.html.add_cookie("username",username,"/",Time.now + 1*60*60*24*365) end -$html << <

Default Username

@@ -112,7 +105,7 @@ $html << <#{username} @@ -124,7 +117,7 @@ if username && !$cgi.include?("edit") CHARSET else - $html << <
@@ -135,9 +128,9 @@ else CHARSET end -$html << "" if username +$d.html << "" if username -$html << <
@@ -145,10 +138,7 @@ $html << < CHARSET -$html << "" -$html << "" - -$html.out($cgi) +$d.out($cgi) end diff --git a/delete_poll.rb b/delete_poll.rb index d2681ed..8a7c41b 100755 --- a/delete_poll.rb +++ b/delete_poll.rb @@ -19,44 +19,23 @@ # along with dudle. If not, see . # ############################################################################ +if __FILE__ == $0 + +load "../dudle.rb" +$d = Dudle.new("Delete Poll") +require "ftools" + QUESTIONS = ["Yes, I know what I am doing!", "I hate these stupid entry fields.", "I am aware of the consequences.", "Please delete this poll."] - -require "cgi" -require "ftools" - -if __FILE__ == $0 - -$cgi = CGI.new - -olddir = File.expand_path(".") -Dir.chdir("..") -load "html.rb" -load "config.rb" -require "poll" -require "yaml" -Dir.chdir(olddir) - -POLLNAME = YAML::load_file("data.yaml").name -POLL = File.basename(File.expand_path(".")) -$html = HTML.new("dudle - #{POLLNAME} - Delete") - -$html.header["Cache-Control"] = "no-cache" - -$html.add_css("../dudle.css") - -$html << "" - if $cgi.include?("confirmnumber") CONFIRM = $cgi["confirmnumber"].to_i if $cgi["confirm"] == QUESTIONS[CONFIRM] Dir.chdir("..") - File.move(POLL, "/tmp/#{POLL}.#{rand(9999999)}") - $html << < + File.move(@d.table.urlsuffix, "/tmp/#{@d.table.urlsuffix}.#{rand(9999999)}") + $d.html << < The poll was deleted successfully!

@@ -71,10 +50,8 @@ if $cgi.include?("confirmnumber")
  • Search something with Google
  • - - SUCCESS - $html.out($cgi) + $d.out($cgi) exit else hint = < -

    #{POLLNAME}

    +$d.html << <Delete this Poll - You want to delete the poll named #{POLLNAME}.
    + You want to delete the poll named #{$d.table.name}.
    This is an irreversible action!
    If you are sure in what you are doing, please type into the form “#{QUESTIONS[CONFIRM]}” #{hint} @@ -117,10 +91,8 @@ $html << <
    - - TABLE -$html.out($cgi) +$d.out($cgi) end diff --git a/dudle.rb b/dudle.rb new file mode 100644 index 0000000..a94dfcf --- /dev/null +++ b/dudle.rb @@ -0,0 +1,91 @@ +############################################################################ +# Copyright 2009 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 . # +############################################################################ + +require "yaml" +require "cgi" + +$cgi = CGI.new + +olddir = File.expand_path(".") +Dir.chdir("..") +require "html" +require "poll" +require "config" +require "charset" +Dir.chdir(olddir) + +class Dudle + attr_reader :html, :table, :urlsuffix + def Dudle.tabs(active_tab) + ret = "
      " + [["Home",".."], + ["",""], + ["Poll","."], + ["History","history.cgi"], + ["Help","help.cgi"], + ["",""], + ["Edit Columns","edit_columns.cgi"], + ["Invite Participants","invite_participants.cgi"], + ["Access Control","access_control.cgi"], + ["Delete Poll","delete_poll.cgi"], + ["",""], + ["Customize","customize.cgi"] + ].each{|tab,file| + case tab + when active_tab + ret += "
    •  #{tab} 
    • " + when "" + ret += "
    • " + else + ret += "
    •  #{tab} 
    • " + end + } + ret += "
    " + ret + end + def initialize(htmltitle, revision=nil) + if revision + @table = YAML::load(VCS.cat(revision, "data.yaml")) + else + @table = YAML::load_file("data.yaml") + end + @urlsuffix = File.basename(File.expand_path(".")) + + @html = HTML.new("dudle - #{@table.name} - #{htmltitle}") + @html.header["Cache-Control"] = "no-cache" + @html.add_css("../dudle.css") + + @html << < +
    -

    #{table.name}

    -

    Add and Remove Columns

    -TABLE +$d << "

    Add and Remove Columns

    " # ADD/REMOVE COLUMN -$html << table.edit_column_htmlform($cgi["editcolumn"],revno) +$d << $d.table.edit_column_htmlform($cgi["editcolumn"],revno) h = VCS.history urevs = h.undorevisions @@ -120,13 +89,13 @@ if rrevs.min hidden["Redo"] = "" end - $html << <
    UNDOREDOREADY ["Undo","Redo"].each{|button| - $html << < TD } - $html << <
    @@ -152,10 +121,9 @@ TD
    READY -#$html << (urevs + rrevs).to_html(curundorev,"") +#$d << (urevs + rrevs).to_html(curundorev,"") -$html << "" -$html.out($cgi) +$d.out($cgi) end diff --git a/help.rb b/help.rb index 923476d..7935aea 100755 --- a/help.rb +++ b/help.rb @@ -19,33 +19,16 @@ # along with dudle. If not, see . # ############################################################################ -require "cgi" - if __FILE__ == $0 -$cgi = CGI.new -olddir = File.expand_path(".") -Dir.chdir("..") -load "html.rb" -load "config.rb" -require "poll" -require "yaml" -Dir.chdir(olddir) - -POLL = YAML::load_file("data.yaml").name -$html = HTML.new("dudle - #{POLL} - Access Control Settings") -$html.header["Cache-Control"] = "no-cache" - -$html.add_css("../dudle.css") - -$html << < -#{Dudle::tabs("Help")} -
    -

    #{POLL}

    +load "../dudle.rb" + +$d = Dudle.new("Help") + +$d << <#{SITEURL} -Send this link via email... +Send this link via email...
    @@ -53,10 +36,7 @@ The link to your poll is: END -$html << "
    " -$html << "" - -$html.out($cgi) +$d.out($cgi) end diff --git a/history.rb b/history.rb index b8c047e..f154fea 100755 --- a/history.rb +++ b/history.rb @@ -19,56 +19,28 @@ # along with dudle. If not, see . # ############################################################################ -require "cgi" -require "yaml" - if __FILE__ == $0 - -$cgi = CGI.new - -olddir = File.expand_path(".") -Dir.chdir("..") -require "html" -require "poll" -load "config.rb" -Dir.chdir(olddir) +load "../dudle.rb" if $cgi.include?("revision") revno=$cgi["revision"].to_i versiontitle = "Poll of Version #{revno}" - table = YAML::load(VCS.cat(revno, "data.yaml")) + $d = Dudle.new("History",revno) else revno = VCS.revno versiontitle = "Current Poll (Version #{revno})" - table = YAML::load_file("data.yaml") + $d = Dudle.new("History") end -$html = HTML.new("dudle - #{table.name} - History") -$html.header["Cache-Control"] = "no-cache" -load "../charset.rb" -$html.add_css("../dudle.css") - -$html << "" -$html << Dudle::tabs("History") - -$html << <
    @@ -139,7 +108,7 @@ UNDOREDOREADY
    -

    #{table.name}

    -TABLE - - - -$html << "

    #{versiontitle}

    " -$html << table.to_html("",false) - -$html << "

    History

    " -$html << "
    " -$html << table.history_selectform($cgi.include?("revision") ? revno : nil, $cgi["history"]) +$d << "

    #{versiontitle}

    " +$d << $d.table.to_html("",false) -$html << table.history_to_html(revno, $cgi["history"]) -$html << "
    " +$d << "

    History

    " +$d << "
    " +$d << $d.table.history_selectform($cgi.include?("revision") ? revno : nil, $cgi["history"]) -$html << "
    " +$d << $d.table.history_to_html(revno, $cgi["history"]) +$d << "" -$html.out($cgi) +$d.out($cgi) end diff --git a/html.rb b/html.rb index 6164d01..3d55b37 100644 --- a/html.rb +++ b/html.rb @@ -80,32 +80,3 @@ HEAD end end -module Dudle - def Dudle.tabs(active_tab) - ret = "
      " - [["Home",".."], - ["",""], - ["Poll","."], - ["History","history.cgi"], - ["Help","help.cgi"], - ["",""], - ["Edit Columns","edit_columns.cgi"], - ["Invite Participants","invite_participants.cgi"], - ["Access Control","access_control.cgi"], - ["Delete Poll","delete_poll.cgi"], - ["",""], - ["Customize","customize.cgi"] - ].each{|tab,file| - case tab - when active_tab - ret += "
    •  #{tab} 
    • " - when "" - ret += "
    • " - else - ret += "
    •  #{tab} 
    • " - end - } - ret += "
    " - ret - end -end diff --git a/invite_participants.rb b/invite_participants.rb index 6c9204a..abb1ddc 100755 --- a/invite_participants.rb +++ b/invite_participants.rb @@ -19,47 +19,23 @@ # along with dudle. If not, see . # ############################################################################ -require "yaml" -require "cgi" - - if __FILE__ == $0 -$cgi = CGI.new - -olddir = File.expand_path(".") -Dir.chdir("..") -require "html" -load "config.rb" -require "poll" -Dir.chdir(olddir) - +load "../dudle.rb" -table = YAML::load_file("data.yaml") +$d = Dudle.new("Invite Participants") if $cgi.include?("add_participant") - table.add_participant("",$cgi["add_participant"],{}) + $d.table.add_participant("",$cgi["add_participant"],{}) end -$html = HTML.new("dudle - #{table.name} - Invite Participants") -$html.header["Cache-Control"] = "no-cache" -load "../charset.rb" -$html.add_css("../dudle.css") - -$html << "" -$html << Dudle::tabs("Invite Participants") - -$html << <
    -

    #{table.name}

    +$d << <
    Invite Participants - #{table.to_html("","invite")} + #{$d.table.to_html("","invite")} TABLE -$html << "" - -$html.out($cgi) +$d.out($cgi) end diff --git a/participate.rb b/participate.rb index 6efca03..f085e8f 100755 --- a/participate.rb +++ b/participate.rb @@ -19,26 +19,14 @@ # along with dudle. If not, see . # ############################################################################ -require "yaml" if __FILE__ == $0 - -require "cgi" - -$cgi = CGI.new - -olddir = File.expand_path(".") -Dir.chdir("..") -require "html" -require "poll" -load "config.rb" -Dir.chdir(olddir) - -table = YAML::load_file("data.yaml") +load "../dudle.rb" +$d = Dudle.new("Poll") if $cgi.include?("add_participant") if $cgi.include?("delete_participant") - table.delete($cgi["olduser"]) + $d.table.delete($cgi["olduser"]) else agreed = {} $cgi.params.each{|k,v| @@ -47,43 +35,27 @@ if $cgi.include?("add_participant") end } - table.add_participant($cgi["olduser"],$cgi["add_participant"],agreed) + $d.table.add_participant($cgi["olduser"],$cgi["add_participant"],agreed) end end -table.add_comment($cgi["commentname"],$cgi["comment"]) if $cgi["comment"] != "" -table.delete_comment($cgi["delete_comment"].to_i) if $cgi.include?("delete_comment") - -$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") +$d.table.add_comment($cgi["commentname"],$cgi["comment"]) if $cgi["comment"] != "" +$d.table.delete_comment($cgi["delete_comment"].to_i) if $cgi.include?("delete_comment") -$html.add_atom("atom.cgi") if File.exists?("../atom.rb") +$d.html.add_css("../print.css","print") - -$html << "" - -$html << Dudle::tabs("Poll") - -$html << < -HEAD +$d.html.add_atom("atom.cgi") if File.exists?("../atom.rb") # TABLE -$html << <
    #{table.name} +$d << <
    - #{table.to_html($cgi['edituser'])} + #{$d.table.to_html($cgi['edituser'])} TABLE -$html << table.comment_to_html - -$html << "" +$d << $d.table.comment_to_html -$html.out($cgi) +$d.out($cgi) end diff --git a/timepollhead.rb b/timepollhead.rb index 4521f26..24958a0 100644 --- a/timepollhead.rb +++ b/timepollhead.rb @@ -17,6 +17,15 @@ # along with dudle. If not, see . # ############################################################################ +# BUGFIX for Time.parse, which handles the zone indeterministically +class << Time + alias_method :old_parse, :parse + def Time.parse(date, now=self.now) + Time.old_parse("2009-10-25 00:30") + Time.old_parse(date) + end +end + class TimePollHead class TimeString attr_reader :date, :time -- cgit v1.2.3