new entry sorting; style updates
authorMichael Wallner <mike@php.net>
Mon, 22 Aug 2016 12:04:58 +0000 (14:04 +0200)
committerMichael Wallner <mike@php.net>
Mon, 22 Aug 2016 12:04:58 +0000 (14:04 +0200)
mdref/Entry.php
mdref/Tree.php
public/index.css
views/edit.phtml
views/footer.phtml
views/index.phtml
views/layout.phtml
views/mdref.phtml
views/sidebar.phtml

index 4febd764604b678ba9e1f658b3ff3d895b479e2c..9135dd788479e04d44e7510fee0cc668948ca95e 100644 (file)
@@ -236,8 +236,10 @@ class Entry implements \IteratorAggregate {
                                ($loose && glob($this->getBasename() . "/*/$glob"));
                } elseif ($this->isRoot()) {
                        return true;
-               } else {
+               } elseif ($this->getBasename() !== "/") {
                        return is_dir($this->getBasename());
+               } else {
+                       return false;
                }
        }
 
index 8f6c7739f6eaca5fea832fe847ae133ad4657823..11cada07293495da26112af7c8e13b66d421bc04 100644 (file)
@@ -8,19 +8,19 @@ class Tree implements \RecursiveIterator {
         * @var \mdref\Repo
         */
        private $repo;
-       
+
        /**
         * List of first level entries
         * @var array
         */
        private $list = array();
-       
+
        /**
         * The list iterator
         * @var array
         */
        private $iter;
-       
+
        /**
         * @param string $path
         * @param \mdref\Repo $repo
@@ -33,11 +33,11 @@ class Tree implements \RecursiveIterator {
                }
                if ($list) {
                        $this->list = array_filter($list, $this->generateFilter($list));
-                       sort($this->list, SORT_STRING);
+                       usort($this->list, $this->generateSorter());
                }
                $this->repo = $repo;
        }
-       
+
        /**
         * @param array $list
         * @return callable
@@ -50,16 +50,58 @@ class Tree implements \RecursiveIterator {
                        if (false !== array_search("$v.md", $list, true)) {
                                return false;
                        }
-                       
+
                        $pi = pathinfo($v);
                        if (isset($pi["extension"]) && "md" !== $pi["extension"]) {
                                return false;
                        }
-                       
+
                        return true;
                };
        }
 
+       /**
+        * @return callable
+        */
+       private function generateSorter() {
+               return function($a, $b) {
+                       $ab = basename($a, ".md");
+                       $bb = basename($b, ".md");
+
+                       if ($ab{0} === ":" && $bb{0} === ":") {
+                               return strcmp($ab, $bb);
+                       } elseif ($ab{0} === ":") {
+                               return -1;
+                       } elseif ($bb{0} === ":") {
+                               return 1;
+                       }
+
+                       $ad = is_dir(dirname($a)."/$ab");
+                       $bd = is_dir(dirname($b)."/$bb");
+
+                       if ($ad && $bd) {
+                               return strcmp($ab, $bb);
+                       } elseif ($ad) {
+                               return -1;
+                       } elseif ($bd) {
+                               return 1;
+                       }
+
+                       $au = preg_match("/^\p{Lu}/", $ab);
+                       $bu = preg_match("/^\p{Lu}/", $bb);
+
+                       if ($au && $bu) {
+                               return strcmp($ab, $bb);
+                       } elseif ($au) {
+                               return -1;
+                       } elseif ($bu) {
+                               return 1;
+                       }
+
+                       return strcmp($ab, $bb);
+               };
+       }
+
        /**
         * Implements \Iterator
         * @return \mdref\Entry
@@ -67,14 +109,14 @@ class Tree implements \RecursiveIterator {
        public function current() {
                return $this->repo->getEntry($this->repo->hasFile(current($this->iter)));
        }
-       
+
        /**
         * Implements \Iterator
         */
        public function next() {
                next($this->iter);
        }
-       
+
        /**
         * Implements \Iterator
         * @return int
@@ -82,7 +124,7 @@ class Tree implements \RecursiveIterator {
        public function key() {
                return key($this->iter);
        }
-       
+
        /**
         * Implements \Iterator
         */
@@ -90,7 +132,7 @@ class Tree implements \RecursiveIterator {
                $this->iter = $this->list;
                reset($this->iter);
        }
-       
+
        /**
         * Implements \Iterator
         * @return bool
@@ -98,7 +140,7 @@ class Tree implements \RecursiveIterator {
        public function valid() {
                return null !== key($this->iter);
        }
-       
+
        /**
         * Implements \RecursiveIterator
         * @return bool
@@ -106,7 +148,7 @@ class Tree implements \RecursiveIterator {
        public function hasChildren() {
                return $this->current()->hasIterator();
        }
-       
+
        /**
         * Implements \RecursiveIterator
         * @return \mdref\Tree
index 4fd8949f03ad57f3bf829e5b29515fc2e58e3da7..b71b5aec5e4c30d266dcf9d45637b05cb2ab0890 100644 (file)
@@ -7,7 +7,7 @@ html, body{
        min-height: 100%;
 }
 body, code {
-       font-family: Inconsolata, 'Courier New', Courier, monospace;
+       font-family: Inconsolata, 'Inconsolata Awesome', 'Andale Mono', Monaco, 'Courier New', Courier, monospace;
 }
 body {
        line-height: 1.5;
@@ -40,12 +40,15 @@ div.page>ul, div.page>div>ul {
        width: auto;
        min-width: 200px;
        padding-right: 1em;
+       padding-bottom: 1em;
+       margin-bottom: 1em;
 }
 .sidebar>ul {
 }
 .sidebar ul {
        margin-left: 1em;
        margin-top: .5em;
+       margin-bottom: 0;
        padding: 0;
        list-style-type: none;
 }
@@ -118,6 +121,23 @@ ul {
        margin-top: 1em;
        margin-bottom: 2em;
 }
+ol {
+       list-style-type: none;
+}
+ol ul {
+       margin-top: 0;
+       margin-bottom: 0;
+}
+ol li {
+       margin-bottom: 0;
+}
+ol>li {
+       font-weight: bold;
+       margin-bottom: .5em;
+}
+ol>li>* {
+       font-weight: normal;
+}
 li {
        margin-bottom: .5em;
 }
@@ -146,25 +166,30 @@ a.permalink {
        color: #2e8b57;
 }
 
+h1, li h3, th, footer {
+       background: #708090;
+       color: #f5f5dc;
+}
+
+h1, footer {
+       margin: 0;
+       max-width: 1200px;
+       padding: 1em;
+}
+
 h1 {
        line-height: 1.5;
        margin-left: 0 !important;
+       padding-left: 2em;
 }
 h1 code {
        font-weight: normal;
        font-size: .9em;
        line-height: 1.33;
 }
-
-footer, h1, li h3, th {
-       background: #708090;
-       color: #f5f5dc;
-}
-
-footer, h1 {
-       margin: 0;
-       max-width: 1200px;
-       padding: 1em;
+h1 a.permalink {
+       left: -.8em;
+       margin-right: -.6em;
 }
 
 li h3 {
@@ -195,11 +220,24 @@ h1 .constant, pre>code .consant, li h3 .constant {
 h1 .var, pre>code .var, li h3 .var {
        color: #f4a460;
 }
-
+h1 {
+       font-size: 125%;
+}
+h2 {
+       font-size: 120%;
+}
+h3 {
+       font-size: 110%;
+}
+h4 {
+       font-size: 100%;
+}
 footer a, h1 a, pre>code a, li h3 a {
        color: #b0e0e6;
 }
-
+li h3 {
+       font-size: 100%;
+}
 li h3 a {
        text-decoration: none;
 }
@@ -247,6 +285,7 @@ table {
 }
 th, td {
        padding: .4em;
+       border-bottom: 1px solid rgba(112, 128, 144, 0.1);
 }
 dt {
        font-weight: bold;
index aabbb024edec32161e8263e8a1eac4026bc9f9e5..dcce1ca7c46fd5fb26ea0f6d3c33b78f9e5fcf92 100644 (file)
@@ -1,3 +1,5 @@
+
 <?php if (isset($listing) && ($entry = $listing->getSelf()) && ($url = $entry->formatEditUrl())) : ?>
+
        <a class="edit" href="<?=$url?>">Edit Page</a>
 <?php endif; ?>
index 12ef7fbd4ac149876618e2d3455fb9798ee59e54..4aff00c4c643cac1a442f3ae4b27108a23d8c3ba 100644 (file)
@@ -1,3 +1,4 @@
+
 <ul>
        <li><a href="https://github.com/m6w6/mdref">mdref-v<?php readfile(__DIR__."/../VERSION") ?></a></li>
        <li><a href="LICENSE">&copy; <?= implode("-", array_unique([2013, idate("Y")])) ?>
index 0baafb841237b52860385c196c26d413a8e974b1..78d95617242e2c7a33bfda605984cc207a3dcd04 100644 (file)
@@ -1,12 +1,15 @@
+
 <h1>mdref</h1>
 
 <?php if (isset($html)) : ?>
        <?= $html ?>
 <?php elseif (isset($text)) : ?>
+
        <p style="white-space:pre-wrap"><?= $esc($text) ?></p>
 <?php elseif (isset($refs)) : ?>
        <?php foreach ($refs as $repo) : /* @var \mdref\Repo $repo */ ?>
                <?php foreach ($repo as $entry) : /* @var \mdref\Entry $entry */ ?>
+
                <h2 id="<?= $anchor($entry->getTitle()) ?>">
                        <a href="<?= $esc($entry->getName()) ?>"
                        ><?= $esc($entry->getTitle()) ?></a></h2>
index 54c0d56a328863c7d6a2b25070fbb4027cffb004..b3e16d5236d9c2b950082c20483aad09f71a91dc 100644 (file)
@@ -16,6 +16,7 @@
                        <link rel="stylesheet" href="index.css">
                <?php endif; ?>
 
+               <link href="https://fonts.googleapis.com/css?family=Inconsolata&subset=latin-ext" rel="stylesheet">
                <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
                <link rel="shortcut icon" href="<?= $baseUrl . "favicon.ico" ?>">
        </head>
                <?php endif; ?>
 
                <?php if (@$_SERVER["SERVER_NAME"] != "localhost") : ?>
-               <div id="disqus_thread"></div>
-               <script>
-                       var disqus_shortname = 'mdref';
-                       var disqus_identifier = '<?=$ref?>';
-                       (function() {
-                               var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
-                               dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
-                               (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
-                       })();
-               </script>
+
+                       <div id="disqus_thread"></div>
+                       <script>
+                               var disqus_shortname = 'mdref';
+                               var disqus_identifier = '<?=$ref?>';
+                               (function() {
+                                       var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
+                                       dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
+                                       (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
+                               })();
+                       </script>
                <?php endif; ?>
 
-               <footer>
-                       <?php include __DIR__."/footer.phtml" ?>
-               </footer>
+                       <footer>
+                               <?php include __DIR__."/footer.phtml" ?>
+
+                       </footer>
                <?php if (isset($baseUrl)) : ?>
+
                        <script src="index.js"></script>
                <?php endif; ?>
+
                </div>
        </body>
 </html>
index 370d8d85b5b7dd03bb1ddf18951be33ddf53ae89..620619be6f6baffb16b9b30a48a4df4cb99fe6c5 100644 (file)
@@ -1,27 +1,34 @@
+
 <?= $file($entry->getPath()) ?>
 
 <?php if ($entry->hasFunctions()) : ?>
+
 <h2 id="Functions:">Functions:</h2>
 <ul>
        <?php foreach($entry as $sub) : if (!$sub->isFunction()) continue; ?>
+
        <li>
                <h3><a href="<?= $esc($sub->getName()) ?>"><?= $esc($sub) ?></a></h3>
                <p><?= $quick($sub->getDescription()) ?></p>
                <p><?= $esc($sub->getTitle()) ?></p>
        </li>
        <?php endforeach; ?>
+
 </ul>
 <?php endif; ?>
 
 <?php if ($entry->hasNsClasses()) : ?>
+
 <h2 id="Namespaces,.Interfaces.and.Classes:">Namespaces, Interfaces and Classes:</h2>
 <ul>
        <?php foreach ($entry as $sub) : if (!$sub->isNsClass()) continue; ?>
+
        <li>
                <h3><a href="<?= $esc($sub->getName()) ?>"><?= $esc($sub) ?></a></h3>
                <p><?= $quick($sub->getDescription()) ?></p>
                <p><?= $esc($sub->getTitle()) ?></p>
        </li>
        <?php endforeach; ?>
+
 </ul>
 <?php endif; ?>
index 8a3956dda2f1a80331570d423424661f6b4a1a02..2c16424c3f311ec5c55b1659fb3fb2dbad53bd80 100644 (file)
+
 <div class="sidebar">
        <?php if (isset($entry)) : ?>
+
        <div class="edit">
                <a href="<?= $entry->getEditUrl() ?>">Edit</a>
        </div>
        <?php endif; ?>
-       <?php 
+
+       <?php
                if (isset($baseUrl) || !isset($entry)) {
                        $up = "./";
                } else {
                        $up = str_repeat("../", count($entry->getParents()));
                }
        ?>
+
        <ul>
                <li>&lsh; <a href="<?= $up ?>">Home</a>
                        <?php if (isset($entry)) : /* @var \mdref\Entry $entry */ ?>
+
                        <ul>
                                <li>
-                                       <?php foreach ($entry->getParents() as $parent) if ($parent->isFile()) : ?>
-                                       &uarr; 
-                                               <a href="<?= $up.$esc($parent->getName()) ?>">
+                                       <?php foreach ($entry->getParents() as $parent) : ?>
+                                               <?php if ($parent->isFile()) : ?>
+
+                                       &uarr; <a href="<?= $up.$esc($parent->getName()) ?>">
                                                        <?= $esc($entry->getRepo()->getEntry($parent)) ?>
+
                                                </a>
                                                <ul>
                                                        <li>
-                                       <?php endif; ?>
-                                                       &circlearrowright; <a href="<?= $up.$esc($entry->getName()) ?>"
-                                                       ><?= $esc($entry) ?></a>
+                                               <?php endif; ?>
+                                       <?php endforeach; ?>
+
+                                                       &circlearrowright; <strong><a href="<?= $up.$esc($entry->getName()) ?>"
+                                                       ><?= $esc($entry) ?></a></strong>
+
+                                                       <?php if ($entry->hasIterator()): ?>
+
                                                        <ul>
                                                                <?php foreach ($entry as $sub) : /* @var \mdref\Entry $sub */ ?>
+
                                                                <li>
                                                                        &rdsh; <a href="<?= $up.$esc($sub->getName()) ?>"
                                                                        ><?= $esc($sub) ?></a>
                                                                </li>
                                                                <?php endforeach; ?>
+
                                                        </ul>
-                                       <?php foreach ($entry->getParents() as $parent) if ($parent->isFile()) : ?>
+                                                       <?php endif; ?>
+
+                                                       <?php if (isset($parent)) : ?>
+                                                               <?php
+                                                               while ($parent && !$parent->isFile()) {
+                                                                       $parent = $parent->getParent();
+                                                               }
+                                                               ?>
+                                                               <?php if ($parent && $parent->hasIterator()) : ?>
+                                                                       <?php
+                                                                       $parent_closed = true;
+                                                                       ?>
+
+                                               </ul>
+                                                                       <?php foreach ($parent as $sub) : ?>
+                                                                               <?php
+                                                                               if ($sub->getName() === $entry->getName()) {
+                                                                                       continue;
+                                                                               }
+                                                                               ?>
+
+                                               <li>&ldsh; <a href="<?= $up.$esc($sub->getName()) ?>"><?= $esc($sub) ?></a></li>
+                                                                       <?php endforeach; ?>
+                                                               <?php endif; ?>
+                                                       <?php endif; ?>
+                                               <?php foreach ($entry->getParents() as $parent) : ?>
+                                                       <?php if (!empty($parent_closed)) : ?>
+                                                               <?php
+                                                               $parent_closed = false;
+                                                               ?>
+                                                       <?php elseif ($parent->isFile()) : ?>
+                                                               <?php if (isset($parent_closed)) : ?>
+                                                                       <?php
+                                                                       unset($parent_closed);
+                                                                       ?>
+                                                               <?php else : ?>
+
                                                </li>
+                                                               <?php endif; ?>
+
                                        </ul>
-                                       <?php endif; ?>
+                                                       <?php endif; ?>
+                                               <?php endforeach; ?>
+
                                </li>
                        </ul>
                        <?php elseif (isset($refs)) : ?>
+
                        <ul>
                                <?php foreach ($refs as $repo) : /* @var \mdref\Repo $repo */ ?>
                                        <?php foreach ($repo as $sub) : /* @var \mdref\Entry $entry */ ?>
+
                                                <li>
                                                        &rdsh; <a href="<?= $esc($sub->getName()) ?>"
                                                        ><?= $esc($sub->getTitle()) ?></a>
                                                </li>
                                        <?php endforeach; ?>
                                <?php endforeach; ?>
+
                        </ul>
                        <?php endif; ?>
+
                </li>
        </ul>
 </div>
-