Skip to content

Instantly share code, notes, and snippets.

Created January 21, 2012 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ca880d489d5dae4c93d0 to your computer and use it in GitHub Desktop.
Save anonymous/ca880d489d5dae4c93d0 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'cgi'
cgi = CGI.new
if cgi['page'].to_str.length > 0
page = cgi['page'].gsub(' ', '').gsub('.', '')
else
page = 'MainPage'
end
if cgi['content'].to_str.length > 0
File.open(page, "w") do |f|
f.write cgi['content']
end
end
if File.exists?(page)
content = File.open(page, "r").read
display = content.split("\n");
title = display.delete_at(0)
display = display.join("\n").gsub("\n", "<p>")
else
content = "#{page}\n\nDescribe #{page} here."
display = "<p>Describe #{page}<a href=\"?mode=edit&page=#{page}\">?</a> here."
title = page
end
display.gsub!(/\[\[(.+?)\]\]/u, '<a href=?page=\1>\1</a>')
print "Content-Type: text/html; charset=utf-8\r\n\r\n"
puts "<!DOCTYPE html>
<html>
<head>
<title>#{title}</title>
<meta charset=UTF-8>
<style type=text/css>
body { background-color: #000; color: #fff; margin: 3em; font-family: sans-serif; }
h1 { color: #cf6a4c; }
p { color: #cda869; }
a:link, a:visited, a:hover, a:active { color: #8f9d60; }
textarea { width: 100%; height: 20em; font-family: sans-serif; font-size: 1em; background-color: #000; color: #fff; border: 0; }
#footer { border-top: 2px solid #999; margin: 2em 0; padding: 1em 0; }
</style>
</head>
<body>"
if cgi['mode'] == 'edit'
puts "<form action=? method=post>
<textarea name=content>#{content}</textarea>
<input type=hidden name=page value=\"#{page}\">
<input type=submit>
</form>"
else
puts "<h1>#{title}</h1>
#{display}
<div id=footer><a href=?>Home</a> &nbsp;&#183;&nbsp; <a href=?mode=edit&page=#{page}>Edit this page</a></div>"
end
puts "</body></html>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment