static generation does not work with overlapping namespaces
authorMichael Wallner <mike@php.net>
Mon, 20 Jul 2015 06:16:41 +0000 (08:16 +0200)
committerMichael Wallner <mike@php.net>
Mon, 20 Jul 2015 06:16:41 +0000 (08:16 +0200)
bin/gen-static [deleted file]
mdref/Action.php
mdref/Generator.php [deleted file]
public/.htaccess
views/layout.phtml

diff --git a/bin/gen-static b/bin/gen-static
deleted file mode 100755 (executable)
index 15e8609..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/env php
-<?php
-
-define("ROOT", dirname(__DIR__));
-define("REFS", getenv("REFPATH") ?: implode(PATH_SEPARATOR, glob(ROOT."/refs/*")));
-
-#ini_set("open_basedir", ROOT.":".REFS);
-
-$loader = require ROOT . "/vendor/autoload.php";
-/* @var $loader \Composer\Autoload\ClassLoader */
-$loader->add("mdref", ROOT);
-
-$g = new mdref\Generator(REFS, @$argv[1]);
-$g->run();
index 3e318be34d4d45af301d5da2309fa35adcea7d90..37b3d51321ebab4400b8400420b621f91e07d5ec 100644 (file)
@@ -59,7 +59,7 @@ class Action extends Observer {
         */
        private function serveCanonical($ctl, $cnn) {
                $ctl->detachAll(Observer\View::class);
-               $ctl->getResponse()->setHeader("Location", $this->baseUrl->mod($cnn));
+               $ctl->getResponse()->setHeader("Location", $this->baseUrl->mod(["path" => $cnn]));
                $ctl->getResponse()->setResponseCode(301);
        }
        
diff --git a/mdref/Generator.php b/mdref/Generator.php
deleted file mode 100644 (file)
index 7a58387..0000000
+++ /dev/null
@@ -1,180 +0,0 @@
-<?php
-
-namespace mdref;
-
-/**
- * Static mdref generator
- */
-class Generator
-{
-       /**
-        * @var \mdref\Reference
-        */
-       private $reference;
-       
-       /**
-        * @var \mdref\Generator\Renderer
-        */
-       private $renderer;
-       
-       /**
-        * Create a new generator
-        * @param string $refs list of reference paths
-        * @param string $dir output directory
-        */
-       public function __construct($refs, $dir = null) {
-               $this->reference = new Reference(explode(PATH_SEPARATOR, $refs));
-               $this->renderer = new Generator\Renderer($dir ?: "public/static");
-       }
-       
-       /**
-        * Run the generator
-        */
-       public function run() {
-               $this->generateRoot();
-               foreach ($this->reference as $repo) {
-                       $iter = new \RecursiveIteratorIterator($repo, 
-                               \RecursiveIteratorIterator::SELF_FIRST);
-                       foreach ($iter as $ref) {
-                               $this->generateEntry($ref);
-                       }
-               }
-       }
-       
-       /**
-        * Generate index.html and LICENSE.html
-        */
-       private function generateRoot() {
-               printf("Generating index ...\n");
-               $data = $this->createPayload(null);
-               $data->ref = "index";
-               $this->renderer->persist($data);
-
-               printf("Generating LICENSE ...\n");
-               $data->text = file_get_contents(__DIR__."/../LICENSE");
-               $data->ref = "LICENSE";
-               $this->renderer->persist($data);
-       }
-       
-       /**
-        * Generate HTML for an entry
-        * @param \mdref\Entry $ref
-        */
-       private function generateEntry(Entry $ref) {
-               printf("Generating %s ...\n", $ref->getName());
-               $data = $this->createPayload($ref);
-               $this->renderer->persist($data);
-       }
-       
-       /**
-        * Create the view payload
-        * @param \mdref\Entry $ref
-        * @param \mdref\Generator\Renderer $view
-        * @return \stdClass
-        */
-       private function createPayload(Entry $ref = null) {
-               $pld = new \stdClass;
-               
-               $pld->quick = [$this->reference, "formatString"];
-               $pld->file = [$this->reference, "formatFile"];
-               $pld->refs = $this->reference;
-               $pld->view = $this->renderer;
-               if ($ref) {
-                       $pld->entry = $ref;
-                       $pld->ref = $ref->getName();
-               }
-               
-               return $pld;
-       }
-}
-
-namespace mdref\Generator;
-
-class Renderer
-{
-       /**
-        * @var string
-        */
-       private $dir;
-
-       /**
-        * @param string $dir output directory
-        */
-       public function __construct($dir = "public/static") {
-               $this->dir = $dir;
-       }
-       
-       /**
-        * HTML entity encode special characters
-        * @param string $string
-        * @return string
-        */
-       public function esc($string) {
-               return htmlspecialchars($string);
-       }
-       
-       /**
-        * Render mdref page
-        * @param \stdClass $pld
-        * @return string
-        */
-       public function render(\stdClass $pld) {
-               $content = "";
-               ob_start(function($data) use(&$content) {
-                       $content .= $data;
-                       return true;
-               });
-               static::renderFile("views/layout.phtml", (array) $pld);
-               ob_end_flush();
-               return $content;
-       }
-
-       /**
-        * Persist mdref page to output directory
-        * @param \stdClass $data
-        */
-       public function persist(\stdClass $data) {
-               $html = $this->render($data);
-               $file = sprintf("%s/%s.html", $this->dir, $data->ref);
-               $this->saveFile($file, $html);
-               $this->linkIndex(dirname($file));
-       }
-       
-       /**
-        * Save data to file (write to $file.tmp and rename to $file)
-        * @param string $file
-        * @param string $data
-        * @throws \Exception
-        */
-       private function saveFile($file, $data) {
-               $dir = dirname($file);
-               if (!is_dir($dir) && !mkdir($dir, 0755, true)) {
-                       throw new \Exception("Failed to create directory '$dir'");
-               }
-               if (!file_put_contents("$file.tmp", $data)) {
-                       throw new \Exception("Failed to save file '$file.tmp'");
-               }
-               if (!rename("$file.tmp", $file)) {
-                       throw new \Exception("Failed to rename to '$file'");
-               }
-       }
-       
-       private function linkIndex($dir) {
-               $index = "$dir.html";
-               $link = "$dir/index.html";
-               if (is_file($index) && !is_file($link)) {
-                       printf("Generating index for '%s'\n", substr($dir, strlen($this->dir)));
-                       link($index, $link);
-               }
-       }
-       
-       /**
-        * Render file
-        */
-       static private function renderFile() {
-               if (func_num_args() > 1) {
-                       extract(func_get_arg(1));
-               }
-               include func_get_arg(0);
-       }
-}
index c236b7325400f01293b541ef8235d1d90e5a2ccc..87e2468f2b6d613e5ecc1007a6b1efd570982463 100644 (file)
@@ -1,7 +1,5 @@
 DirectorySlash Off
 RewriteEngine On
-RewriteRule ^static.*\.html - [L]
-RewriteRule ^(static/.+) $1.html [L]
 RewriteCond %{REQUEST_FILENAME} -f [OR]
 RewriteCond %{REQUEST_FILENAME} -d [OR]
 RewriteCond %{REQUEST_FILENAME} -l
index 05367b98d1f65fb6120d88d0bb5aeaee0a89085f..6cc571ba21b44ef569da08627d54063b57b7a4fc 100644 (file)
                        <base href="<?= $baseUrl ?>">
                        <meta http-equiv="Content-Location" content="<?= $baseUrl . $ref ?>">
                        <link rel="stylesheet" href="index.css">
-               <?php else: ?>
-                       <style type="text/css">
-                               <?= file_get_contents(__DIR__."/../public/index.css"); ?>
-                       </style>
                <?php endif; ?>
                
                <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
                </footer>
                <?php if (isset($baseUrl)) : ?>
                        <script src="index.js"></script>
-               <?php else : ?>
-                       <script type="application/javascript">
-                               <?= file_get_contents(__DIR__."/../public/index.js"); ?>
-                       </script>
                <?php endif; ?>
        </body>
 </html>