From: Michael Wallner Date: Wed, 30 Oct 2013 17:47:50 +0000 (+0100) Subject: flush X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=333f749f9ae65fecd6b52b06fde3dceda1579470;p=mdref%2Fmdref flush --- diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..816ff40 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Copyright (c) 2013, Michael Wallner . +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/http.md b/http.md new file mode 100644 index 0000000..6175e26 --- /dev/null +++ b/http.md @@ -0,0 +1,5 @@ +# namespace http + +This is pecl_http-v2. + +This documentation is work-in-progress. diff --git a/http/Env.md b/http/Env.md index d75dbf2..d4245bb 100644 --- a/http/Env.md +++ b/http/Env.md @@ -6,6 +6,6 @@ The http\Env class provides static methods to manipulate and inspect the server' The http\Env module overrides PHP's builtin POST data parser to be run also if the request method is not POST. Additionally it will handle -```application/json``` payloads if ```ext/json``` is available. Successfully +application/json payloads if ext/json is available. Successfully parsed JSON will be put right into the $_POST array. diff --git a/http/Env/Request.md b/http/Env/Request.md index 5c4b32f..63de534 100644 --- a/http/Env/Request.md +++ b/http/Env/Request.md @@ -2,13 +2,13 @@ ## Constants: -> None. +None. ## Properties: -* ```protected $query = NULL``` +* protected $query = NULL The request's query parameters. ($_GET) -* ```protected $form = NULL``` +* protected $form = NULL The request's form parameters. ($_POST) -* ```protected $files = NULL``` +* protected $files = NULL The request's form uploads. ($_FILES) diff --git a/http/Env/Request/__construct.md b/http/Env/Request/__construct.md index e69de29..307d73a 100644 --- a/http/Env/Request/__construct.md +++ b/http/Env/Request/__construct.md @@ -0,0 +1,7 @@ +# void http\Env\Request::__construct(void) + +Instantiate the server's current HTTP request. + +## Params: + +None. diff --git a/http/Env/getRequestBody.md b/http/Env/getRequestBody.md index 512128d..eaadc0d 100644 --- a/http/Env/getRequestBody.md +++ b/http/Env/getRequestBody.md @@ -4,12 +4,12 @@ Retreive the current HTTP request's body. ## Parameters: -* Optional ```string $body_class_name``` +* Optional string $body_class_name A user class extending http\Body. ## Returns: -* ```http\Message\Body``` instance representing the request body +* http\Message\Body instance representing the request body ## Throws: diff --git a/http/Env/getRequestHeader.md b/http/Env/getRequestHeader.md index b33718b..17e87b7 100644 --- a/http/Env/getRequestHeader.md +++ b/http/Env/getRequestHeader.md @@ -4,11 +4,11 @@ Retrieve one or all headers of the current HTTP request. ## Parameters: -* Optional ```string $header_name``` +* Optional string $header_name The key of a header to retrieve. ## Returns: -* ```NULL```, if $header_name was not found -* ```string```, the compound header when $header_name was found -* ```array``` of all headers if $header_name was not specified +* NULL, if $header_name was not found +* string, the compound header when $header_name was found +* array of all headers if $header_name was not specified diff --git a/http/Env/getResponseCode.md b/http/Env/getResponseCode.md index 11feca8..bb5dba0 100644 --- a/http/Env/getResponseCode.md +++ b/http/Env/getResponseCode.md @@ -4,9 +4,9 @@ Get the HTTP response code to send. ## Parameters: -> None. +None. ## Returns: -* ```int```, the HTTP response code. +* int, the HTTP response code. diff --git a/http/Env/getResponseHeader.md b/http/Env/getResponseHeader.md index c30a4d7..7bdd37a 100644 --- a/http/Env/getResponseHeader.md +++ b/http/Env/getResponseHeader.md @@ -4,11 +4,11 @@ Get one or all HTTP response headers to be sent. ## Parameters: -* Optional ```string $header_name``` +* Optional string $header_name The name of the response header to retrieve. ## Returns: -* ```string```, the compound value of the response header to send -* ```NULL```, if the header was not found -* ```array```, of all response headers, if $header_name was not specified +* string, the compound value of the response header to send +* NULL, if the header was not found +* array, of all response headers, if $header_name was not specified diff --git a/http/Env/getResponseStatusForAllCodes.md b/http/Env/getResponseStatusForAllCodes.md index 2e37783..f31941f 100644 --- a/http/Env/getResponseStatusForAllCodes.md +++ b/http/Env/getResponseStatusForAllCodes.md @@ -4,12 +4,12 @@ Retrieve a list of all known HTTP response status. ## Parameters: -> None. +None. ## Returns: -* ```array``` mapping of the form \[ +* array mapping of the form \[ ... - ```int $code``` => ```string $status``` + int $code => string $status ... \] diff --git a/http/Env/getResponseStatusForCode.md b/http/Env/getResponseStatusForCode.md index d2bfa85..e97b60f 100644 --- a/http/Env/getResponseStatusForCode.md +++ b/http/Env/getResponseStatusForCode.md @@ -4,11 +4,11 @@ Retrieve the string representation of specified HTTP response code. ## Parameters: -* ```int $code``` +* int $code The HTTP response code to get the string representation for. ## Returns: -* ```string```, the HTTP response status message -* empty ```string```, if no message for this code was found +* string, the HTTP response status message +* empty string, if no message for this code was found diff --git a/http/Env/negotiate.md b/http/Env/negotiate.md index 0230bc6..f7b53d2 100644 --- a/http/Env/negotiate.md +++ b/http/Env/negotiate.md @@ -6,16 +6,16 @@ Generic negotiator. For specific client negotiation see http\Env::negotiateConte ## Params: -* ```string $params``` +* string $params HTTP header parameter's value to negotiate. -* ```array $supported``` +* array $supported List of supported negotiation operands. -* Optional ```string $prim_typ_sep``` +* Optional string $prim_typ_sep A "primary type separator", i.e. that would be a hyphen for content language negotiation (en-US, de-DE, etc.). -* Optional reference ```array &$result``` +* Optional reference array &$result Out parameter recording negotiation results. ## Returns: -* ```NULL```, if negotiation fails. -* ```string```, the closest match negotiated, or the default (first entry of $supported). +* NULL, if negotiation fails. +* string, the closest match negotiated, or the default (first entry of $supported). diff --git a/http/Env/negotiateCharset.md b/http/Env/negotiateCharset.md index 20cc01b..c13020b 100644 --- a/http/Env/negotiateCharset.md +++ b/http/Env/negotiateCharset.md @@ -6,12 +6,12 @@ Negotiate the client's preferred character set. ## Params: -* ```array $supported``` +* array $supported List of supported content character sets. -* Optional reference ```array &$result``` +* Optional reference array &$result Out parameter recording negotiation results. ## Returns: -* ```NULL```, if negotiation fails. -* ```string```, the negotiated character set. +* NULL, if negotiation fails. +* string, the negotiated character set. diff --git a/http/Env/negotiateContentType.md b/http/Env/negotiateContentType.md index 510e33f..7b2ea31 100644 --- a/http/Env/negotiateContentType.md +++ b/http/Env/negotiateContentType.md @@ -6,20 +6,20 @@ Negotiate the client's preferred MIME content type. ## Params: -* ```array $supported``` +* array $supported List of supported MIME content types. -* Optional reference ```array &$result``` +* Optional reference array &$result Out parameter recording negotiation results. ## Returns: -* ```NULL```, if negotiation fails. -* ```string```, the negotiated content type. +* NULL, if negotiation fails. +* string, the negotiated content type. ## Example: -A client indicates his accepted MIME content types by sending an ```Accept``` -header. The static ```http\Env``` class provides a facility to negotiate the +A client indicates his accepted MIME content types by sending an Accept +header. The static http\Env class provides a facility to negotiate the client's preferred content type: None. +None. ## Returns: -* ```string```, the serialized form of the HTTP header (i.e. "Name: value"). +* string, the serialized form of the HTTP header (i.e. "Name: value"). diff --git a/http/Header/getParams.md b/http/Header/getParams.md index d3645c2..98fd885 100644 --- a/http/Header/getParams.md +++ b/http/Header/getParams.md @@ -4,15 +4,15 @@ Create a parameter list out of the HTTP header value. ## Params: -* Optional ```mixed $ps``` +* Optional mixed $ps The parameter separator(s). -* Optional ```mixed $as``` +* Optional mixed $as The argument separator(s). -* Optional ```mixed``` +* Optional mixed The value separator(s). -* Optional ```int $flags``` +* Optional int $flags The modus operandi. See http\Params constants. ## Returns: -* ```http\Params``` instance +* http\Params instance diff --git a/http/Header/match.md b/http/Header/match.md index 7635cd2..7fd74bf 100644 --- a/http/Header/match.md +++ b/http/Header/match.md @@ -4,11 +4,11 @@ Match the HTTP header's value against provided $value according to $flags. ## Params: -* ```string $value``` +* string $value The comparison value. -* Optional ```int $flags``` +* Optional int $flags The modus operandi. See http\Header constants. ## Returns: -* ```bool```, whether $value matches the header value according to $flags. +* bool, whether $value matches the header value according to $flags. diff --git a/http/Header/negotiate.md b/http/Header/negotiate.md index af0547f..32daaa0 100644 --- a/http/Header/negotiate.md +++ b/http/Header/negotiate.md @@ -2,20 +2,20 @@ Negotiate the header's value against a list of supported values in $supported. Negotiation operation is adopted according to the header name, i.e. if the -header being negotiated is ```Accept```, then a slash is used as primary type -separator, and if the header is ```Accept-Language``` respectively, a hyphen is +header being negotiated is Accept, then a slash is used as primary type +separator, and if the header is Accept-Language respectively, a hyphen is used instead. > ***NOTE:*** The first elemement of $supported serves as a default if no operand matches. ## Params: -* ```array $supported``` +* array $supported The list of supported values to negotiate. -* Optional reference ```array &$result``` +* Optional reference array &$result Out parameter recording the negotiation results. ## Returns: -* ```NULL```, if negotiation fails. -* ```string```, the closest match negotiated, or the default (first entry of $supported). +* NULL, if negotiation fails. +* string, the closest match negotiated, or the default (first entry of $supported). diff --git a/http/Header/parse.md b/http/Header/parse.md index c1965c1..0db884c 100644 --- a/http/Header/parse.md +++ b/http/Header/parse.md @@ -4,11 +4,11 @@ Parse HTTP headers. ## Params: -* ```string $header``` +* string $header The complete string of headers. -* Optional ```string $header_class``` +* Optional string $header_class A class extending http\Header. ## Returns: -* ```array``` of parsed headers, where the elements are instances of $header_class if specified. +* array of parsed headers, where the elements are instances of $header_class if specified. diff --git a/http/Header/serialize.md b/http/Header/serialize.md index 2afe46e..9a73a5b 100644 --- a/http/Header/serialize.md +++ b/http/Header/serialize.md @@ -4,8 +4,8 @@ Implements Serializable. ## Params: -> None. +None. ## Returns: -* ```string```, serialized representation of HTTP header (i.e. "Name: value") +* string, serialized representation of HTTP header (i.e. "Name: value") diff --git a/http/Header/toString.md b/http/Header/toString.md index 2eec780..6197fa7 100644 --- a/http/Header/toString.md +++ b/http/Header/toString.md @@ -4,8 +4,8 @@ Convenience method. Alias of http\Header::serialize(). ## Params: -> None. +None. ## Returns: -* ```string```, the serialized form of the HTTP header (i.e. "Name: value"). +* string, the serialized form of the HTTP header (i.e. "Name: value"). diff --git a/http/Header/unserialize.md b/http/Header/unserialize.md index 2ccd6c4..3a40de6 100644 --- a/http/Header/unserialize.md +++ b/http/Header/unserialize.md @@ -4,6 +4,6 @@ Implements Serializable. ## Params: -* ```string $serialized``` +* string $serialized The serialized HTTP header (i.e. "Name: value") diff --git a/http/Params.md b/http/Params.md index f479223..3d80b88 100644 --- a/http/Params.md +++ b/http/Params.md @@ -4,34 +4,34 @@ Parse, interpret and compose HTTP (header) parameters. ## Constants: -* ```DEF_PARAM_SEP``` +* DEF_PARAM_SEP The default parameter separator (","). -* ```DEF_ARG_SEP``` +* DEF_ARG_SEP The default argument separator (";"). -* ```DEF_VAL_SEP``` +* DEF_VAL_SEP The default value separator ("="). -* ```COOKIE_PARAM_SEP``` +* COOKIE_PARAM_SEP TBD -* ```PARSE_RAW``` +* PARSE_RAW Do not interpret the parsed parameters. -* ```PARSE_DEFAULT``` +* PARSE_DEFAULT Interpret input as default formatted parameters. -* ```PARSE_URLENCODED``` +* PARSE_URLENCODED Urldecode single units of parameters, arguments and values. -* ```PARSE_DIMENSION``` +* PARSE_DIMENSION Parse sub dimensions indicated by square brackets. -* ```PARSE_QUERY``` +* PARSE_QUERY Parse URL query string (same as http\Params::PARSE_URLENCODED|http\Params::PARSE_DIMENSION). ## Properties: -* ```public $params = NULL``` +* public $params = NULL The (parsed) parameters. -* ```public $param_sep = http\Header::DEF_PARAM_SEP``` +* public $param_sep = http\Params::DEF_PARAM_SEP The parameter separator(s). -* ```public $arg_sep = http\Header::DEF_ARG_SEP``` +* public $arg_sep = http\Params::DEF_ARG_SEP The argument separator(s). -* ```public $val_sep = http\Header::DEF_VAL_SEP``` +* public $val_sep = http\Params::DEF_VAL_SEP The value separator(s). -* ```public $flags = http\Params::PARSE_DEFAULT``` +* public $flags = http\Params::PARSE_DEFAULT The modus operandi of the parser. See http\Params::PARSE_* constants. diff --git a/http/Params/__construct.md b/http/Params/__construct.md index 76034a9..ff2a296 100644 --- a/http/Params/__construct.md +++ b/http/Params/__construct.md @@ -4,15 +4,15 @@ Instantiate a new HTTP (header) parameter set. ## Params: -* Optional ```mixed $params``` +* Optional mixed $params Pre-parsed parameters or a string to be parsed. -* Optional ```mixed $ps``` +* Optional mixed $ps The parameter separator(s). -* Optional ```mixed $as``` +* Optional mixed $as The argument separator(s). -* Optional ```mixed $vs``` +* Optional mixed $vs The value separator(s). -* Optional ```int $flags``` +* Optional int $flags The modus operandi. See http\Params::PARSE_* constants. ## Throws: diff --git a/http/Params/__toString.md b/http/Params/__toString.md index c1bd91c..050445a 100644 --- a/http/Params/__toString.md +++ b/http/Params/__toString.md @@ -5,8 +5,8 @@ Returns a stringified version of the parameters. ## Params: -> None. +None. ## Returns: -* ```string``` version of the parameters. +* string version of the parameters. diff --git a/http/Params/offsetExists.md b/http/Params/offsetExists.md index b3d7b29..0e46228 100644 --- a/http/Params/offsetExists.md +++ b/http/Params/offsetExists.md @@ -4,9 +4,9 @@ Implements ArrayAccess. ## Params: -* ```string $name``` +* string $name The offset to look after. ## Returns: -* ```bool``` Existence. +* bool Existence. diff --git a/http/Params/offsetGet.md b/http/Params/offsetGet.md index cc96a9a..4c68c8b 100644 --- a/http/Params/offsetGet.md +++ b/http/Params/offsetGet.md @@ -4,9 +4,9 @@ Implements ArrayAccess. ## Params: -* ```string $name``` +* string $name The offset to retrieve. ## Returns: -* ```mixed```, contents at offset. +* mixed, contents at offset. diff --git a/http/Params/offsetSet.md b/http/Params/offsetSet.md index 4a24d41..55932af 100644 --- a/http/Params/offsetSet.md +++ b/http/Params/offsetSet.md @@ -4,8 +4,8 @@ Implements ArrayAccess. ## Params: -* ```string $name``` +* string $name The offset to modify. -* ```mixed $value``` +* mixed $value The value to set. diff --git a/http/Params/offsetUnset.md b/http/Params/offsetUnset.md index 4c5af78..0593022 100644 --- a/http/Params/offsetUnset.md +++ b/http/Params/offsetUnset.md @@ -4,6 +4,6 @@ Implements ArrayAccess. ## Params: -* ```string $name``` +* string $name The offset to delete. diff --git a/http/Params/toArray.md b/http/Params/toArray.md index e7ca841..4686bf1 100644 --- a/http/Params/toArray.md +++ b/http/Params/toArray.md @@ -4,8 +4,8 @@ Convenience method that simply returns http\Params::$params. ## Params: -> None. +None. ## Returns: -* ```array``` of paramters. +* array of paramters. diff --git a/http/Params/toString.md b/http/Params/toString.md index 34400be..7776ece 100644 --- a/http/Params/toString.md +++ b/http/Params/toString.md @@ -4,8 +4,8 @@ Returns a stringified version of the parameters. ## Params: -> None. +None. ## Returns: -* ```string``` version of the parameters. +* string version of the parameters. diff --git a/index.css b/index.css index b61f515..949bcbc 100644 --- a/index.css +++ b/index.css @@ -6,12 +6,25 @@ body { font-family: monospace; font-size: 1.5em; margin: 0; - padding: 4em 0 0 0; + padding: 0; } body>* { + margin-left: 1em; +} + +.sidebar { + float: right; + width: 400px; + background: #f0f0f0; + border-bottom-left-radius: 10px; + padding: 0; + margin-bottom: 1em; margin-left: 2em; - margin-right: 2em; +} +.sidebar>ul { + paddinng: 1em; + margin-left: 1em; } code { @@ -24,22 +37,17 @@ code { } h1 { - position: fixed; - top: 0; - left: 0; - width: 100%; margin: 0; padding: 1em; } p { color: #3f3f3f; - margin: 1em; + margin: 1em 2em; } blockquote { padding: 1em; border-radius: 4px; - max-width: 1000px; } blockquote, blockquote p { color: #f0f0f0; @@ -57,10 +65,17 @@ a { .var { color: #800000; } +.constant { + color: #2e8b57; +} .invert, h1, blockquote, blockquote p { - background: #030303; - color: #f0f0f0; + background: #708090; + color: #f5f5dc; +} + +.invert .constant, h1 .constant, blockquote .constant { + color: #98fb98; } .invert .var, h1 .var, blockquote .var { @@ -70,4 +85,3 @@ a { .invert a, h1 a, blockquote a { color: #b0e0e6; } - diff --git a/index.js b/index.js index 6334108..2f65772 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,13 @@ +function is_constant(s) { + return s.length > 3 && s.toUpperCase(s) === s; +} + +function is_variable(s) { + return s.substring(0,1) === "$"; +} + function type(s) { + var i, j, t; // nothing if (!s.match(/[a-zA-Z]/)) { @@ -15,6 +24,7 @@ function type(s) { case "array": case "object": case "callable": + case "mixed": return ""; // keywords @@ -35,16 +45,22 @@ function type(s) { return ""; } - var is_namespace, is_method; - - if ((is_method = (s.indexOf("::") !== -1)) || (is_namespace = (s.indexOf("\\") !== -1))) { - return ""; + // class members + if (-1 !== (i = s.indexOf("::"))) { + t = s.substring(i+2); + if (!is_constant(t) && !is_variable(t)) { + // methods + return ""; + } + } + if (-1 !== (j = s.indexOf("\\"))) { + return ""; } switch (s.toLowerCase()) { // variables default: - if (s.substring(0,1) !== "$") { + if (!is_variable(s)) { break; } // special constants @@ -55,8 +71,8 @@ function type(s) { } // constants - if (s.toUpperCase() === s) { - return ""; + if (is_constant(s)) { + return ""; } } function node(s) { @@ -94,8 +110,32 @@ function walk(i, e) { } }); } -$(document).ready(function() { - //console.log("ready"); +function hashchange() { + if (location.hash.length > 1) { + var hash = location.hash.substring(1); + + $(is_variable(hash) ? ".var" : ".constant").each(function(i, c) { + + if (c.textContent === hash) { + var $c = $(c); + + $(window).scrollTop($c.offset().top - 100); + $c.fadeOut("slow").queue(function(next) { + this.style.color = "red"; + next(); + }).fadeIn("fast").fadeOut("fast").queue(function(next) { + this.style.color = ""; + next(); + }).fadeIn("slow"); + return false; + } + }); + } +} + +$(function() { $("h1,h2,h3,h4,h5,h6,p,li,code").each(walk); + $(window).on("hashchange", hashchange); + hashchange(); }); diff --git a/index.php b/index.php index 160fed5..b210984 100644 --- a/index.php +++ b/index.php @@ -2,8 +2,6 @@ error_reporting(E_ALL &~ E_DEPRECATED); -define("OUTPUT", fopen("php://memory", "w+")); - function cut(array $lines, array $specs) { $delim = "[[:space:]]+"; $bytes = []; @@ -69,98 +67,139 @@ function ns($file) { } function urlpath($dir, $file) { - return (strlen($dir) ? $dir . "/" : "") . urlencode($file); + return (strlen($dir) ? $dir . "/" : "") . basename($file, ".md"); } -function ls($dir, $invert = false) { - fprintf(OUTPUT, "
    \n"); - foreach (scandir($dir) as $file) { - $dir = trim($dir, "./"); - $html = ""; - if ($file === ".") { - continue; - } elseif ($file === "..") { - if ($dir === "" || $invert) { +function ls($dir) { + $dir = rtrim(is_dir($dir) ? $dir : dirname($dir) ."/". basename($dir, ".md"), "/"); + printf("
      \n"); + printf("
    • Home
    • \n"); + if ($dir !== "." && ($dn = dirname($dir)) !== ".") { + printf("
    • %s
    • \n", + urlpath($dir, ".."), + ns($dn)); + } + if (is_dir($dir)) { + if ($dir !== ".") { + printf("
    • %s
    • \n", ns($dir)); + } + foreach (scandir($dir) as $file) { + /* ignore dot-files */ + if ($file{0} === ".") { continue; } - $name = sprintf("namespace %s", ns(dirname($dir))); - } elseif (!$invert && is_dir("./$dir/$file")) { - $name = sprintf("namespace %s", ns("./$dir/$file")); - } elseif (!$invert && ctype_upper($file{0})) { - $name = join(" ", cut(head("./$dir/$file"), ["f"=>"1-2"])); - } elseif (!$invert || ctype_upper($file{0})) { - continue; - } else { - $name = ns($dir)."::".basename($file, ".md"); - $html = "

      ".join(" ", cut(head("./$dir/$file"), ["f"=>"1-"]))."

      "; + + $path = "$dir/$file"; + + if (is_file($path)) { + $pi = pathinfo($path); + /* ignore files not ending in .md */ + if (!isset($pi["extension"]) || $pi["extension"] != "md") { + continue; + } + if (!ctype_upper($file{0}) && !is_dir("$dir/".$pi["filename"])) { + continue; + } + } else { + /* ignore directories where an companying file exists */ + if (is_file("$path.md")) { + continue; + } + } + + printf("
    • %s
    • \n", + urlpath($dir, $file), + ns("$dir/".basename($file, ".md"))); } - - fprintf(OUTPUT, "
    • %s%s
    • \n", - urlpath($dir, $file), - htmlspecialchars($name), - $html); } - fprintf(OUTPUT, "
    \n"); + + printf("
\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); + printf("

Methods:

\n"); + $dir = $pi["dirname"] . "/" . $pi["filename"]; + if (is_dir($dir)) { + printf("
    \n"); + foreach (scandir($dir) as $file) { + if (!is_file("$dir/$file") || ctype_upper($file{0})) { + continue; + } + printf("
  • %s

    %s

  • \n", + basename($file, ".md"), + join(" ", cut(head("$dir/$file"), ["f"=>"1-"])) + ); + } + printf("
\n"); + } } } function md($file) { - $r = fopen($file, "r"); - $md = MarkdownDocument::createFromStream($r); - $md->compile(); - $md->writeHtml(OUTPUT); - unset($md); - fclose($r); + $file = rtrim($file, "/"); + if (is_file($file) || is_file($file .= ".md")) { + $r = fopen($file, "r"); + $md = MarkdownDocument::createFromStream($r); + $md->compile(); + echo $md->getHtml(); + fclose($r); + ml($file); + } else { + printf("

Quick Markdown Doc Browser

\n"); + printf("

v0.1.0

\n"); + printf("

"); + ob_start(function($s) { + return nl2br(htmlspecialchars($s)); + }); + readfile("LICENSE"); + ob_end_flush(); + printf("

\n"); + } +} - // BS Markdown seeks around... - fseek(OUTPUT, 0, SEEK_END); - - ml($file); + +function index($pn) { + ?> + + + + + <?=ns($pn)?> + + + + + + + + + + "text/css", "js"=>"application/javascript"]; $r = new http\Env\Request; $u = new http\Url($r->getRequestUrl()); -$t = ["css"=>"text/css", "js"=>"application/javascript"]; +$s = new http\Env\Response; 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; +default: + ob_start($s); + index(".".$u->path); + ob_end_flush(); + $s->send(); + break; } -if (is_dir(".".$u->path)) { - ls(".".$u->path); -} else { - md(".".$u->path); -} - -?> - - - - -<?=$u->path?> - - - - - - - -