diff options
Diffstat (limited to '')
l--------- | customize.cgi | 1 | ||||
-rwxr-xr-x | customize.rb | 10 | ||||
-rw-r--r-- | dudle.rb | 90 | ||||
-rw-r--r-- | html.rb | 19 | ||||
-rwxr-xr-x | index.cgi | 41 | ||||
-rwxr-xr-x | participate.rb | 1 |
6 files changed, 90 insertions, 72 deletions
diff --git a/customize.cgi b/customize.cgi new file mode 120000 index 0000000..26de213 --- /dev/null +++ b/customize.cgi @@ -0,0 +1 @@ +customize.rb
\ No newline at end of file diff --git a/customize.rb b/customize.rb index 54f7995..0cb79a7 100755 --- a/customize.rb +++ b/customize.rb @@ -22,7 +22,8 @@ if __FILE__ == $0 -load "../dudle.rb" +$:.unshift("..") +require "dudle" $d = Dudle.new("Customize") @@ -65,11 +66,6 @@ $d << <<CHARSET </div> CHARSET - -a = [["default","css=dudle.css"], - ["Print","css=print.css"], - ["PrimeLife","css=primelife.css"], - ["TU Dresden","css=tud.css"]] css = $cgi.cookies["css"][0] css = $cgi["css"] if $cgi.include?("css") css ||= "dudle.css" @@ -77,7 +73,7 @@ $d.html.add_cookie("css",css,"/",Time.now + (1*60*60*24*365 * (css == "dudle.css $d << <<CSS <div id='config_stylesheet'> <h3>Stylesheet</h3> -#{choosetable("Stylesheet settings",a,"css=#{css}")} +#{choosetable("Stylesheet settings",$d.css.collect{|name,href| [name,"css=#{href}"]},"css=#{css}")} </div> CSS @@ -22,31 +22,32 @@ require "cgi" $cgi = CGI.new -olddir = File.expand_path(".") -Dir.chdir("..") +$:.unshift("..") require "html" require "poll" require "config" require "charset" -Dir.chdir(olddir) class Dudle - attr_reader :html, :table, :urlsuffix - def Dudle.tabs(active_tab) + attr_reader :html, :table, :urlsuffix, :css + def tabs(active_tab) ret = "<div id='tabs'><ul>" - [["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| + tabs = [] + tabs << ["Home",".."] + if @is_poll + tabs << ["",""] + tabs << ["Poll","."] + tabs << ["History","history.cgi"] + tabs << ["Help","help.cgi"] + tabs << ["",""] + tabs << ["Edit Columns","edit_columns.cgi"] + tabs << ["Invite Participants","invite_participants.cgi"] + tabs << ["Access Control","access_control.cgi"] + tabs << ["Delete Poll","delete_poll.cgi"] + tabs << ["",""] + end + tabs << ["Customize","customize.cgi"] + tabs.each{|tab,file| case tab when active_tab ret += "<li id='active_tab' > #{tab} </li> " @@ -59,33 +60,64 @@ class Dudle ret += "</ul></div>" ret end + def initialize(htmltitle, revision=nil) - if revision - @table = YAML::load(VCS.cat(revision, "data.yaml")) + if File.exists?("data.yaml") && !File.stat("data.yaml").directory? + @is_poll = true + basedir = ".." + if revision + @table = YAML::load(VCS.cat(revision, "data.yaml")) + else + @table = YAML::load_file("data.yaml") + end + @urlsuffix = File.basename(File.expand_path(".")) + @title = @table.name + @html = HTML.new("dudle - #{@title} - #{htmltitle}") + @html.header["Cache-Control"] = "no-cache" else - @table = YAML::load_file("data.yaml") + @is_poll = false + basedir = "." + @title = "dudle" + @html = HTML.new(@title) 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") + + @css = [["default","dudle.css"], + ["print" ,"print.css"]] + Dir.open("#{basedir}/css/").each{|f| + if f =~ /\.css$/ + name = "" + File.open("#{basedir}/css/#{f}","r").each_line{|l| + name = l.scan(/\/\* Name: (.*) \*\/$/).flatten[0] + break + } + @css << [name,"css/#{f}"] + end + } + default = $cgi["css"] + default = $cgi.cookies["css"][0] if default == "" + @css.each{|title,href| + @html.add_css("../#{href}",title,href == default) + } @html << <<HEAD <body> -<div id='header' /> -#{Dudle.tabs(htmltitle)} +<div id='header1'></div> +<div id='header2'></div> +<div id='header3'></div> +#{tabs(htmltitle)} <div id='main'> - <h1>#{@table.name}</h1> + <h1>#{@title}</h1> HEAD end + def out(cgi) @html << "</div></body>" @html.out(cgi) end + def <<(htmlbodytext) @html << htmlbodytext end end - @@ -27,7 +27,7 @@ class HTML @header["charset"] = "utf-8" @body = "" - @css = {} + @css = [] @atom = [] end def head @@ -37,21 +37,26 @@ class HTML <meta http-equiv="Content-Style-Type" content="text/css" /> <title>#{@title}</title> HEAD + + @css = [@css[0]] + @css[1..-1].sort @css.each{|title,href| - 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" + ret += "<link rel='stylesheet' type='text/css' href='#{href}' title='#{title}'/>\n" + ret += "<link rel='stylesheet' type='text/css' href='#{href}' title='print' media='print' />\n" if title == "print" } @atom.each{|href| - ret += "<link rel='alternate' type='application/atom+xml' href='#{href}' />" + ret += "<link rel='alternate' type='application/atom+xml' href='#{href}' />\n" } ret += "</head>" ret end - def add_css(href, title = "default") - @css[title] ||= [] - @css[title] << href + 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 @@ -19,36 +19,24 @@ # along with dudle. If not, see <http://www.gnu.org/licenses/>. # ############################################################################ -require "yaml" -require "cgi" - - if __FILE__ == $0 -$cgi = CGI.new if File.exists?("config.rb") - load "config.rb" + require "dudle" else puts "\nPlease configure me in the file config.rb" exit end -require "poll" -require "html" -$html = HTML.new("dudle") -load "charset.rb" -$html.add_css("dudle.css") -$htlm.add_atom("atom.cgi") if File.exists?("atom.cgi") - - $html << "<body id='main'><h1>dudle</h1>" +$d = Dudle.new("Home") if $cgi.include?("create_poll") && $cgi.include?("poll_url") POLLNAME=$cgi["create_poll"] if $cgi["poll_url"] == "" POLLURL = `pwgen -1`.chomp else - POLLURL=$cgi["poll_url"] + OLLURL=$cgi["poll_url"] end @@ -71,18 +59,16 @@ if $cgi.include?("create_poll") && $cgi.include?("poll_url") } Poll.new(POLLNAME,$cgi["poll_type"]) Dir.chdir("..") - escapedsite = SITEURL + CGI.escapeHTML(CGI.escape(POLLURL)) + "/edit_columns.cgi" - escapedsite.gsub!("+"," ") - $html.header["status"] = "REDIRECT" - $html.header["Cache-Control"] = "no-cache" - $html.header["Location"] = escapedsite - $html << "The poll was created successfully. The link to your new poll is:<br /><a href=\"#{escapedsite}\">#{escapedsite}</a>" + $d.html.header["status"] = "REDIRECT" + $d.html.header["Cache-Control"] = "no-cache" + $d.html.header["Location"] = SITEURL + "/edit_columns.cgi" + $d << "The poll was created successfully. The link to your new poll is:<br /><a href=\"#{escapedsite}\">#{escapedsite}</a>" end end -unless $html.header["status"] == "REDIRECT" +unless $d.html.header["status"] == "REDIRECT" - $html << <<CREATE + $d << <<CREATE <h2>Create New Poll</h2> <form method='post' action='.'> <table class='settingstable' summary='Create a new Poll'> @@ -114,7 +100,7 @@ unless $html.header["status"] == "REDIRECT" </tr> CREATE if defined?(createnotice) - $html << <<NOTICE + $d << <<NOTICE <tr> <td colspan='2' class='error'> #{createnotice} @@ -122,15 +108,14 @@ CREATE </tr> NOTICE end - $html << <<CREATE + $d << <<CREATE </table> </form> CREATE - $html << NOTICE - $html << "</body>" + $d << NOTICE end -$html.out($cgi) +$d.out($cgi) end diff --git a/participate.rb b/participate.rb index f085e8f..7152ca9 100755 --- a/participate.rb +++ b/participate.rb @@ -42,7 +42,6 @@ end $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") -$d.html.add_css("../print.css","print") $d.html.add_atom("atom.cgi") if File.exists?("../atom.rb") |