From 277cfe1f0e09b05e6615ce87603672e0f305520a Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Wed, 30 Oct 2013 10:02:36 +0100 Subject: [PATCH] initialize --- index.css | 73 ++++++++++++++++++++++++ index.js | 101 +++++++++++++++++++++++++++++++++ index.php | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 340 insertions(+) create mode 100644 index.css create mode 100644 index.js create mode 100644 index.php diff --git a/index.css b/index.css new file mode 100644 index 0000000..b61f515 --- /dev/null +++ b/index.css @@ -0,0 +1,73 @@ +* { + font-size: 99.9%; +} + +body { + font-family: monospace; + font-size: 1.5em; + margin: 0; + padding: 4em 0 0 0; +} + +body>* { + margin-left: 2em; + margin-right: 2em; +} + +code { + display: inline-block; + border-radius: 2px; + padding: 0px 2px 2px 2px; + background: #e0e0e0; + color: #606060; + box-shadow: 0 0 1px #999; +} + +h1 { + position: fixed; + top: 0; + left: 0; + width: 100%; + margin: 0; + padding: 1em; +} +p { + color: #3f3f3f; + margin: 1em; +} + +blockquote { + padding: 1em; + border-radius: 4px; + max-width: 1000px; +} +blockquote, blockquote p { + color: #f0f0f0; +} +ul { + margin-bottom: 2em; +} +li { + margin-bottom: .5em; +} +a { + color: #2f4f4f; +} + +.var { + color: #800000; +} + +.invert, h1, blockquote, blockquote p { + background: #030303; + color: #f0f0f0; +} + +.invert .var, h1 .var, blockquote .var { + color: #f4a460; +} + +.invert a, h1 a, blockquote a { + color: #b0e0e6; +} + diff --git a/index.js b/index.js new file mode 100644 index 0000000..6334108 --- /dev/null +++ b/index.js @@ -0,0 +1,101 @@ +function type(s) { + + // nothing + if (!s.match(/[a-zA-Z]/)) { + return; + } + + switch (s) { + // types + case "void": + case "bool": + case "int": + case "float": + case "string": + case "array": + case "object": + case "callable": + return ""; + + // keywords + case "class": + case "interface": + case "namespace": + case "extends": + case "implements": + case "public": + case "protected": + case "private": + case "static": + case "final": + case "abstract": + // phrases + case "Optional": + case "optional": + return ""; + } + + var is_namespace, is_method; + + if ((is_method = (s.indexOf("::") !== -1)) || (is_namespace = (s.indexOf("\\") !== -1))) { + return ""; + } + + switch (s.toLowerCase()) { + // variables + default: + if (s.substring(0,1) !== "$") { + break; + } + // special constants + case "null": + case "true": + case "false": + return ""; + } + + // constants + if (s.toUpperCase() === s) { + return ""; + } +} +function node(s) { + //console.log("node", s); + + var t; + + if ((t = type(s))) { + return $(t).text(s); + } + return document.createTextNode(s); +} +function wrap(n) { + var $n = $(n) + var a = []; + + $n.text().split(/([^a-zA-Z_\\\$:]+)/).forEach(function(v) { + a.push(node(v)); + }); + $n.replaceWith(a); +} +function walk(i, e) { + //console.log("walk", i, e); + + e && $.each(e.childNodes, function(i, n) { + //console.log(n.nodeName); + switch (n.nodeName) { + case "A": + break; + case "#text": + wrap(n); + break; + default: + walk(n); + } + }); +} +$(document).ready(function() { + //console.log("ready"); + + $("h1,h2,h3,h4,h5,h6,p,li,code").each(walk); +}); diff --git a/index.php b/index.php new file mode 100644 index 0000000..160fed5 --- /dev/null +++ b/index.php @@ -0,0 +1,166 @@ + $value) { + switch ($spec) { + case "d": + $delim = $value; + break; + case "b": + $bytes = $value; + break; + case "f": + $fields = $value; + break; + } + } + + $result = []; + if ($bytes) { + $func = "substr"; + } else { + $func = function($a, $o = 0, $l = 0) { + return join(" ", array_slice($a, $o, $l ? $l+1 : count($a)-$o)); + }; + } + foreach ($lines as $line) { + if ($bytes) { + $spec = $bytes; + } else { + $line = split($delim, $line); + $spec = $fields; + } + + if ($spec[0] == "-") { + $result[] = $func($line, 0, $spec[1]); + } elseif ($spec[1] == "-") { + if (empty($spec[2])) { + $result[] = $func($line, $spec[0]); + } else { + $result[] = $func($line, $spec[0], $spec[2]-$spec[0]); + } + } else { + $result[] = $line{$spec[0]}; + } + } + return $result; +} + +function head($file, $lines = 1) { + $ld = []; + if (($fd = fopen($file, "r"))) { + while ($lines--) { + $ld[] = fgets($fd); + } + } + return $ld; +} + +function ns($file) { + return str_replace("/", "\\", str_replace("//", "/", trim($file, "/."))); +} + +function urlpath($dir, $file) { + return (strlen($dir) ? $dir . "/" : "") . urlencode($file); +} + +function ls($dir, $invert = false) { + fprintf(OUTPUT, "\n"); +} + +function ml($file) { + $pi = pathinfo($file); + if (ctype_upper($pi["filename"][0])) { + fprintf(OUTPUT, "

Methods:

\n"); + $el = $pi["dirname"] . "/" . $pi["filename"]; + ls($el, true); + } +} + +function md($file) { + $r = fopen($file, "r"); + $md = MarkdownDocument::createFromStream($r); + $md->compile(); + $md->writeHtml(OUTPUT); + unset($md); + fclose($r); + + // BS Markdown seeks around... + fseek(OUTPUT, 0, SEEK_END); + + ml($file); +} + +$r = new http\Env\Request; +$u = new http\Url($r->getRequestUrl()); +$t = ["css"=>"text/css", "js"=>"application/javascript"]; + +switch($u->path) { +case "/index.js": +case "/index.css": + $s = new http\Env\Response; + $s->setHeader("Content-type", $t[pathinfo($u->path, PATHINFO_EXTENSION)]); + $s->setBody(new http\Message\Body(fopen(basename($u->path), "r"))); + $s->send(); + exit; +} + +if (is_dir(".".$u->path)) { + ls(".".$u->path); +} else { + md(".".$u->path); +} + +?> + + + + +<?=$u->path?> + + + + + + + + -- 2.30.2