From 2ee3a79d20f6873673258883a0402cf1a57f1f7b Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 28 Jan 2012 01:25:08 -0500 Subject: [PATCH] Some pretty awesome stuff. --- build.py | 2 +- pages/bash.mako | 2 +- pages/earwigbot.mako | 2 + pages/extensions.mako | 2 + pages/index.mako | 27 +++++++++++++ pages/support/footer.mako | 5 ++- pages/support/header.mako | 19 +++++++-- pages/surveyor.mako | 2 + pages/swmt.mako | 2 + static/css/main.css | 46 ++++++++++++++++----- static/js/potd.js | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 192 insertions(+), 17 deletions(-) create mode 100644 pages/earwigbot.mako create mode 100644 pages/extensions.mako create mode 100644 pages/surveyor.mako create mode 100644 pages/swmt.mako create mode 100644 static/js/potd.js diff --git a/build.py b/build.py index e9a30d7..9fa9607 100755 --- a/build.py +++ b/build.py @@ -17,7 +17,7 @@ def myapp(environ, start_response): start_response("200 OK", [("Content-Type", "text/html")]) lookup = TemplateLookup(directories=["{{pages_dir}}"]) template = Template(filename="{{src}}", module_directory="{{temp_dir}}", - lookup=lookup) + lookup=lookup, format_exceptions=True) return [template.render(environ=environ).encode("utf8")] if __name__ == "__main__": diff --git a/pages/bash.mako b/pages/bash.mako index 7dbd4ee..8f2724f 100644 --- a/pages/bash.mako +++ b/pages/bash.mako @@ -5,7 +5,7 @@ "I make tools and tool accessories." ] %>\ -<%def name="bash()">${choice(bashes)}\ +<%def name="get_bash()">${choice(bashes)}\ <%include file="/support/header.mako" args="environ=environ, title='Bash'"/>
    % for bash in bashes: diff --git a/pages/earwigbot.mako b/pages/earwigbot.mako new file mode 100644 index 0000000..911199d --- /dev/null +++ b/pages/earwigbot.mako @@ -0,0 +1,2 @@ +<%include file="/support/header.mako" args="environ=environ, title='EarwigBot Status'"/> +<%include file="/support/footer.mako" args="environ=environ"/> diff --git a/pages/extensions.mako b/pages/extensions.mako new file mode 100644 index 0000000..e987d60 --- /dev/null +++ b/pages/extensions.mako @@ -0,0 +1,2 @@ +<%include file="/support/header.mako" args="environ=environ, title='File Extension Checker'"/> +<%include file="/support/footer.mako" args="environ=environ"/> diff --git a/pages/index.mako b/pages/index.mako index b380f20..0eb400d 100644 --- a/pages/index.mako +++ b/pages/index.mako @@ -1,2 +1,29 @@ +<%! + from os import path + import time + + tools = [ + ("Home", "home", "index", True, None), + ("Copyvio Detector", "copyvios", "copyvios", False, "Blah"), + ("EarwigBot Status", "earwigbot", "earwigbot", True, "Blah"), + ("File Extension Checker", "extensions", "extensions", False, "Blah"), + ("Contribution Surveyor", "surveyor", "surveyor", False, "Blah"), + ("SWMT Helper", "swmt", "swmt", False, "Blah"), + ] +%>\ +<% + root = path.dirname(environ["SCRIPT_NAME"]) + pretty = path.split(root)[0] +%>\ +<%def name="get_tools()"><% return tools %>\ <%include file="/support/header.mako" args="environ=environ, title='Home', slug='home'"/> +

    My Tools

    + % for name, tool, link, complete, desc in tools: + % if desc: +
    +

    ${tool}: ${name}

    +

    ${desc}

    +
    + % endif + % endfor <%include file="/support/footer.mako" args="environ=environ"/> diff --git a/pages/support/footer.mako b/pages/support/footer.mako index 110875b..ef08547 100644 --- a/pages/support/footer.mako +++ b/pages/support/footer.mako @@ -1,5 +1,5 @@ <%page args="environ"/>\ -<%namespace name="bash" file="/bash.mako"/>\ +<%namespace name="bash" file="/bash.mako" import="get_bash"/>\ <%! from os import path %>\ @@ -19,8 +19,9 @@

    Copyright © 2009–2012 Ben Kurtovic • \ Contact • \ View Source • \ + Background • \ Valid XHTML 1.0 Strict
    - "${bash.bash()}" + "${get_bash()}"

    diff --git a/pages/support/header.mako b/pages/support/header.mako index 1689430..ed0a88a 100644 --- a/pages/support/header.mako +++ b/pages/support/header.mako @@ -1,13 +1,18 @@ <%page args="environ, title, slug=None"/>\ +<%namespace name="index" file="/index.mako" import="get_tools"/>\ <%! + from itertools import count from os import path %>\ <% + tools = get_tools() root = path.dirname(environ["SCRIPT_NAME"]) this = environ["PATH_INFO"] pretty = path.split(root)[0] if not slug: slug = path.split(this)[1] + if slug.endswith(".fcgi"): + slug = slug[:-5] %>\ @@ -15,10 +20,18 @@ ${title} - earwig@toolserver + - +
    \ No newline at end of file diff --git a/pages/surveyor.mako b/pages/surveyor.mako new file mode 100644 index 0000000..35d7a0a --- /dev/null +++ b/pages/surveyor.mako @@ -0,0 +1,2 @@ +<%include file="/support/header.mako" args="environ=environ, title='Contribution Surveyor'"/> +<%include file="/support/footer.mako" args="environ=environ"/> diff --git a/pages/swmt.mako b/pages/swmt.mako new file mode 100644 index 0000000..e608f4a --- /dev/null +++ b/pages/swmt.mako @@ -0,0 +1,2 @@ +<%include file="/support/header.mako" args="environ=environ, title='SWMT Helper'"/> +<%include file="/support/footer.mako" args="environ=environ"/> diff --git a/static/css/main.css b/static/css/main.css index f6dfc70..331f91c 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -2,7 +2,8 @@ body { font-family: helvetica, arial, clean, sans-serif; font-size: 14px; color: #000; - background-color: #E0E0E0; + /*background-color: #E0E0E0;*/ + background-color: #000; } ul, ol { @@ -12,7 +13,7 @@ ul, ol { div#header { margin: 20px; padding: 2px 15px 2px 15px; - border: 1px solid #999; + border: 1px solid #777; background-color: #FFF; } @@ -20,7 +21,7 @@ div#container { line-height: 1.5; margin: 0 20px 90px 20px; padding: 2px 15px 2px 15px; - border: 1px solid #999; + border: 1px solid #777; background-color: #FFF; } @@ -43,17 +44,19 @@ div#footer { } div#foot-divider { - border-bottom: 1px solid #999; + border-bottom: 1px solid #777; } -h1#head { +p#heading { font-size: 3em; + font-weight: bold; margin: 15px 0 12px 0; } -h2#links { - font-size: 1.75em; - margin: 8px 0 8px 0; +p#links { + font-size: 1.65em; + font-weight: bold; + margin: 8px 0 14px 0; } table#footer-box { @@ -61,16 +64,39 @@ table#footer-box { height: 100%; } -span.light { color: #CCC; } +div.toolbox { + margin: 15px 0 15px 0; + padding: 0 6px 0 6px; + border: 1px solid #999; + background-color: #F5F5F5; +} + +p.toolname { + font-size: 18px; + margin: 6px 0 6px 0; + background-color: #E7E7E7; +} + +p.tooldesc { + margin: 6px 0 6px 0; +} + +span.light { color: #CCC; } +span.medium { color: #AAA; } a:link { color: #373; text-decoration: none; } a:visited { color: #373; text-decoration: none; } a:hover { color: #040; text-decoration: underline; } a:active { color: #404; text-decoration: underline; } +a.black:link { color: #000; } +a.black:visited { color: #000; } +a.black:hover { color: #000; } +a.black:active { color: #000; } + a.dark:link { color: #777; } a.dark:visited { color: #777; } -a.dark:hover { color: #555; } +a.dark:hover { color: #777; } a.dark:active { color: #333; } a.mid:link { color: #AAA; } diff --git a/static/js/potd.js b/static/js/potd.js new file mode 100644 index 0000000..b6b24d0 --- /dev/null +++ b/static/js/potd.js @@ -0,0 +1,100 @@ +function potd_set_background() { + var d = new Date(); + var callback = "like_a_boss"; + var date = (d.getUTCFullYear()) + "-" + zero_pad(d.getUTCMonth() + 1, 2) + "-" + zero_pad(d.getUTCDate(), 2); + var base = "http://commons.wikimedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=Template:Potd/"; + var url = base + date + "&callback=" + callback; + + var script = document.createElement("script"); + var head = document.getElementsByTagName("head")[0]; + + window[callback] = function(data) { + head.removeChild(script); + parse_file_name(data); + }; + + script.src = url; + head.appendChild(script); +} + +function parse_file_name(data) { + var content = ""; + var res = data["query"]["pages"]; + for (pageid in res) { + content = res[pageid]["revisions"][0]["*"]; + } + var filename = /\{\{Potd filename\|(1=)?(.*?)\|.*?\}\}/.exec(content)[2]; + + var callback = "like_a_faust"; + var base = "http://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&iiprop=url|size&format=json&titles=File:"; + var url = base + escape(filename) + "&callback=" + callback; + + var script = document.createElement("script"); + var head = document.getElementsByTagName("head")[0]; + + window[callback] = function(data) { + head.removeChild(script); + parse_file_url(data, escape(filename.replace(/ /g, "_"))); + }; + + script.src = url; + head.appendChild(script); +} + +function parse_file_url(data, filename) { + var url = ""; + var descurl = ""; + var imgwidth = 1024; + var imgheight = 768; + + var res = data["query"]["pages"]; + for (pageid in res) { + r = res[pageid]["imageinfo"][0]; + url = r["url"]; + descurl = r["descriptionurl"]; + imgwidth = r["width"]; + imgheight = r["height"]; + } + + url = url.replace(/\/commons\//, "/commons/thumb/"); + var s = get_window_size(); + var winwidth = s[0]; + var winheight = s[1]; + + var width = winwidth; + if (imgwidth/imgheight > winwidth/winheight) { + width = Math.round((imgwidth/imgheight) * winheight); + } + url += "/" + width + "px-" + filename; + + document.body.style.backgroundImage="url('" + url + "')"; + document.getElementById("bg_image_link").href = descurl; +} + +function zero_pad(value, length) { + value = String(value); + length = length || 2; + while (value.length < length) { + value = "0" + value; + } + return value; +} + +function get_window_size() { + // See http://www.javascripter.net/faq/browserw.htm + var width = 1024, + height = 768; + if (document.body && document.body.offsetWidth && document.body.offsetHeight) { + width = document.body.offsetWidth; + height = document.body.offsetHeight; + } + if (document.compatMode=="CSS1Compat" && document.documentElement && document.documentElement.offsetWidth && document.documentElement.offsetHeight) { + width = document.documentElement.offsetWidth; + height = document.documentElement.offsetHeight; + } + if (window.innerWidth && window.innerHeight) { + width = window.innerWidth; + height = window.innerHeight; + } + return [width, height]; +}