From 36209cf65906c2cc6cbc1972737329057c5ded0d Mon Sep 17 00:00:00 2001
From: Andrii Vasyliev <sol@hiqdev.com>
Date: Wed, 23 Nov 2016 08:40:22 +0000
Subject: [PATCH 1/7] Added `ApiRenderer::renderDefaultValue`, fixed #38

close #122
---
 CHANGELOG.md                   |  2 +-
 templates/html/ApiRenderer.php | 36 ++++++++++++++++++++++++++++++++--
 2 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index daf3c42b..7f2682ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@ Yii Framework 2 apidoc extension Change Log
 2.0.7 under development
 -----------------------
 
-- no changes in this release.
+- Enh #38: Fixed display of default values given as octal or hex notation (hiqsol)
 
 
 2.0.6 November 22, 2016
diff --git a/templates/html/ApiRenderer.php b/templates/html/ApiRenderer.php
index 7cc22abd..12b7a465 100644
--- a/templates/html/ApiRenderer.php
+++ b/templates/html/ApiRenderer.php
@@ -247,7 +247,7 @@ public function renderPropertySignature($property, $context = null)
         return '<span class="signature-defs">' . implode(' ', $definition) . '</span> '
             . '<span class="signature-type">' . $this->createTypeLink($property->types, $context) . '</span>'
             . ' ' . $this->createSubjectLink($property, $property->name) . ' '
-            . ApiMarkdown::highlight('= ' . ($property->defaultValue === null ? 'null' : $property->defaultValue), 'php');
+            . ApiMarkdown::highlight('= ' . $this->renderDefaultValue($property->defaultValue), 'php');
     }
 
     /**
@@ -262,7 +262,7 @@ public function renderMethodSignature($method, $context = null)
                 . ($param->isPassedByReference ? '<b>&</b>' : '')
                 . ApiMarkdown::highlight(
                     $param->name
-                    . ($param->isOptional ? ' = ' . $param->defaultValue : ''),
+                    . ($param->isOptional ? ' = ' . $this->renderDefaultValue($param->defaultValue) : ''),
                     'php'
                 );
         }
@@ -283,6 +283,38 @@ public function renderMethodSignature($method, $context = null)
             . str_replace('  ', ' ', ' ( ' . implode(', ', $params) . ' )');
     }
 
+    /**
+     * Renders the default value.
+     * @param mixed $value
+     * @return string
+     * @since 2.0.7
+     */
+    public function renderDefaultValue($value)
+    {
+        if ($value === null) {
+            return 'null';
+        }
+
+        // special numbers which are usually used in octal or hex notation
+        static $specials = [
+            // file permissions
+            '420' => '0644',
+            '436' => '0664',
+            '438' => '0666',
+            '493' => '0755',
+            '509' => '0775',
+            '511' => '0777',
+            // colors used in yii\captcha\CaptchaAction
+            '2113696' => '0x2040A0',
+            '16777215' => '0xFFFFFF',
+        ];
+        if (isset($specials[$value])) {
+            return $specials[$value];
+        }
+
+        return $value;
+    }
+
     /**
      * @inheritdoc
      */

From 2fb2ff29f0380b50a34171b37ae2bbdd317eebc0 Mon Sep 17 00:00:00 2001
From: Carsten Brandt <mail@cebe.cc>
Date: Sun, 4 Dec 2016 15:43:53 +0100
Subject: [PATCH 2/7] only display TOC when there is more than one headline

---
 CHANGELOG.md            | 1 +
 helpers/ApiMarkdown.php | 7 ++++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f2682ed..72ac0669 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ Yii Framework 2 apidoc extension Change Log
 -----------------------
 
 - Enh #38: Fixed display of default values given as octal or hex notation (hiqsol)
+- Enh: Display TOC only if there is more than one headline (cebe)
 
 
 2.0.6 November 22, 2016
diff --git a/helpers/ApiMarkdown.php b/helpers/ApiMarkdown.php
index 2f70848b..9431a397 100644
--- a/helpers/ApiMarkdown.php
+++ b/helpers/ApiMarkdown.php
@@ -70,11 +70,12 @@ public function parse($text)
      */
     protected function applyToc($content)
     {
-        // generate TOC
-        if (!empty($this->headings)) {
+        // generate TOC if there is more than one headline
+        if (!empty($this->headings) && count($this->headings) > 1) {
             $toc = [];
-            foreach ($this->headings as $heading)
+            foreach ($this->headings as $heading) {
                 $toc[] = '<li>' . Html::a(strip_tags($heading['title']), '#' . $heading['id']) . '</li>';
+            }
             $toc = '<div class="toc"><ol>' . implode("\n", $toc) . "</ol></div>\n";
             if (strpos($content, '</h1>') !== false)
                 $content = str_replace('</h1>', "</h1>\n" . $toc, $content);

From 568156d2eecbd19a1229d40ad4d20102f19fdbcc Mon Sep 17 00:00:00 2001
From: Carsten Brandt <mail@cebe.cc>
Date: Mon, 5 Dec 2016 02:38:43 +0100
Subject: [PATCH 3/7] extracted markdown code highlighting to a trait

---
 CHANGELOG.md                       |  1 +
 helpers/ApiMarkdown.php            | 66 +-----------------------
 helpers/MarkdownHighlightTrait.php | 83 ++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+), 65 deletions(-)
 create mode 100644 helpers/MarkdownHighlightTrait.php

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72ac0669..0fe5e722 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ Yii Framework 2 apidoc extension Change Log
 
 - Enh #38: Fixed display of default values given as octal or hex notation (hiqsol)
 - Enh: Display TOC only if there is more than one headline (cebe)
+- Enh: Extracted markdown code highlighting to a trait `MarkdownHighlightTrait` (cebe)
 
 
 2.0.6 November 22, 2016
diff --git a/helpers/ApiMarkdown.php b/helpers/ApiMarkdown.php
index 9431a397..4bdd2861 100644
--- a/helpers/ApiMarkdown.php
+++ b/helpers/ApiMarkdown.php
@@ -8,8 +8,6 @@
 namespace yii\apidoc\helpers;
 
 use cebe\markdown\GithubMarkdown;
-use DomainException;
-use Highlight\Highlighter;
 use yii\apidoc\models\TypeDoc;
 use yii\apidoc\renderers\BaseRenderer;
 use yii\helpers\Html;
@@ -25,6 +23,7 @@
 class ApiMarkdown extends GithubMarkdown
 {
     use ApiMarkdownTrait;
+    use MarkdownHighlightTrait;
 
     /**
      * @var BaseRenderer
@@ -85,69 +84,6 @@ protected function applyToc($content)
         return $content;
     }
 
-    /**
-     * @var Highlighter
-     */
-    private static $highlighter;
-
-    /**
-     * @inheritdoc
-     */
-    protected function renderCode($block)
-    {
-        if (self::$highlighter === null) {
-            self::$highlighter = new Highlighter();
-            self::$highlighter->setAutodetectLanguages([
-                'apache', 'nginx',
-                'bash', 'dockerfile', 'http',
-                'css', 'less', 'scss',
-                'javascript', 'json', 'markdown',
-                'php', 'sql', 'twig', 'xml',
-            ]);
-        }
-        try {
-            if (isset($block['language'])) {
-                $result = self::$highlighter->highlight($block['language'], $block['content'] . "\n");
-                return "<pre><code class=\"hljs {$result->language} language-{$block['language']}\">{$result->value}</code></pre>\n";
-            } else {
-                $result = self::$highlighter->highlightAuto($block['content'] . "\n");
-                return "<pre><code class=\"hljs {$result->language}\">{$result->value}</code></pre>\n";
-            }
-        } catch (DomainException $e) {
-            echo $e;
-            return parent::renderCode($block);
-        }
-    }
-
-    /**
-     * Highlights code
-     *
-     * @param string $code code to highlight
-     * @param string $language language of the code to highlight
-     * @return string HTML of highlighted code
-     * @deprecated since 2.0.5 this method is not used anymore, highlight.php is used for highlighting
-     */
-    public static function highlight($code, $language)
-    {
-        if ($language !== 'php') {
-            return htmlspecialchars($code, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
-        }
-
-        if (strncmp($code, '<?php', 5) === 0) {
-            $text = @highlight_string(trim($code), true);
-        } else {
-            $text = highlight_string("<?php ".trim($code), true);
-            $text = str_replace('&lt;?php', '', $text);
-            if (($pos = strpos($text, '&nbsp;')) !== false) {
-                $text = substr($text, 0, $pos) . substr($text, $pos + 6);
-            }
-        }
-        // remove <code><span style="color: #000000">\n and </span>tags added by php
-        $text = substr(trim($text), 36, -16);
-
-        return $text;
-    }
-
     /**
      * @inheritDoc
      */
diff --git a/helpers/MarkdownHighlightTrait.php b/helpers/MarkdownHighlightTrait.php
new file mode 100644
index 00000000..5a949dbd
--- /dev/null
+++ b/helpers/MarkdownHighlightTrait.php
@@ -0,0 +1,83 @@
+<?php
+/**
+ * @link http://www.yiiframework.com/
+ * @copyright Copyright (c) 2008 Yii Software LLC
+ * @license http://www.yiiframework.com/license/
+ */
+
+namespace yii\apidoc\helpers;
+
+use DomainException;
+use Highlight\Highlighter;
+
+/**
+ * MarkdownHighlightTrait provides code highlighting functionality for Markdown Parsers.
+ *
+ * @since 2.0.7
+ * @author Carsten Brandt <mail@cebe.cc>
+ */
+trait MarkdownHighlightTrait
+{
+    /**
+     * @var Highlighter
+     */
+    private static $highlighter;
+
+    /**
+     * @inheritdoc
+     */
+    protected function renderCode($block)
+    {
+        if (self::$highlighter === null) {
+            self::$highlighter = new Highlighter();
+            self::$highlighter->setAutodetectLanguages([
+                'apache', 'nginx',
+                'bash', 'dockerfile', 'http',
+                'css', 'less', 'scss',
+                'javascript', 'json', 'markdown',
+                'php', 'sql', 'twig', 'xml',
+            ]);
+        }
+        try {
+            if (isset($block['language'])) {
+                $result = self::$highlighter->highlight($block['language'], $block['content'] . "\n");
+                return "<pre><code class=\"hljs {$result->language} language-{$block['language']}\">{$result->value}</code></pre>\n";
+            } else {
+                $result = self::$highlighter->highlightAuto($block['content'] . "\n");
+                return "<pre><code class=\"hljs {$result->language}\">{$result->value}</code></pre>\n";
+            }
+        } catch (DomainException $e) {
+            echo $e;
+            return parent::renderCode($block);
+        }
+    }
+
+    /**
+     * Highlights code
+     *
+     * @param string $code code to highlight
+     * @param string $language language of the code to highlight
+     * @return string HTML of highlighted code
+     * @deprecated since 2.0.5 this method is not used anymore, highlight.php is used for highlighting
+     */
+    public static function highlight($code, $language)
+    {
+        if ($language !== 'php') {
+            return htmlspecialchars($code, ENT_NOQUOTES | ENT_SUBSTITUTE, 'UTF-8');
+        }
+
+        if (strncmp($code, '<?php', 5) === 0) {
+            $text = @highlight_string(trim($code), true);
+        } else {
+            $text = highlight_string("<?php ".trim($code), true);
+            $text = str_replace('&lt;?php', '', $text);
+            if (($pos = strpos($text, '&nbsp;')) !== false) {
+                $text = substr($text, 0, $pos) . substr($text, $pos + 6);
+            }
+        }
+        // remove <code><span style="color: #000000">\n and </span>tags added by php
+        $text = substr(trim($text), 36, -16);
+
+        return $text;
+    }
+}

From 69eca9d4161a3d078f647309b705df2b58929fff Mon Sep 17 00:00:00 2001
From: Carsten Brandt <mail@cebe.cc>
Date: Tue, 6 Dec 2016 16:04:45 +0100
Subject: [PATCH 4/7] added httpclient and shell extensions

---
 templates/bootstrap/RendererTrait.php | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/templates/bootstrap/RendererTrait.php b/templates/bootstrap/RendererTrait.php
index 92b40e9b..6c9310bc 100644
--- a/templates/bootstrap/RendererTrait.php
+++ b/templates/bootstrap/RendererTrait.php
@@ -27,10 +27,12 @@ trait RendererTrait
         'elasticsearch',
         'faker',
         'gii',
+        'httpclient',
         'imagine',
         'jui',
         'mongodb',
         'redis',
+        'shell',
         'smarty',
         'sphinx',
         'swiftmailer',

From b5c7ec88c8aa2c6ddb22ea93c6ac1e48bd19516e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ricardo=20P=C3=A9rez?= <ricpelo@gmail.com>
Date: Mon, 20 Nov 2017 09:37:25 +0100
Subject: [PATCH 5/7] Set alias @bower and @npm to
 @vendor/{bower-asset,@npm-asset} (#153)

* Set alias @bower and @npm to @vendor/{bower-asset,@npm-asset}

Fixes #152.

* Check if dirs exists, as @cebe suggested

* Check only $vendorPath/{bower,npm}[-asset]

* Check if $vendorPath !== null before setting @bower, @npm
---
 CHANGELOG.md |  1 +
 apidoc       | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0fe5e722..8e76c47d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@ Yii Framework 2 apidoc extension Change Log
 -----------------------
 
 - Enh #38: Fixed display of default values given as octal or hex notation (hiqsol)
+- Enh #152: Set `@bower` and `@npm` aliases dependent on the existing directories (ricpelo)
 - Enh: Display TOC only if there is more than one headline (cebe)
 - Enh: Extracted markdown code highlighting to a trait `MarkdownHighlightTrait` (cebe)
 
diff --git a/apidoc b/apidoc
index 0dd7d372..5074e84b 100755
--- a/apidoc
+++ b/apidoc
@@ -49,6 +49,26 @@ $application = new yii\console\Application([
 ]);
 if ($vendorPath !== null) {
     $application->setVendorPath($vendorPath);
+    $bowerDirs = [
+        "$vendorPath/bower",
+        "$vendorPath/bower-asset",
+    ];
+    foreach ($bowerDirs as $dir) {
+        if (file_exists($dir)) {
+            Yii::setAlias('@bower', $dir);
+            break;
+        }
+    }
+    $npmDirs = [
+        "$vendorPath/npm",
+        "$vendorPath/npm-asset",
+    ];
+    foreach ($npmDirs as $dir) {
+        if (file_exists($dir)) {
+            Yii::setAlias('@npm', $dir);
+            break;
+        }
+    }
 }
 $exitCode = $application->run();
 exit($exitCode);

From 2891bf2eca3357d5ef6084355ca55838d590d61e Mon Sep 17 00:00:00 2001
From: Carsten Brandt <mail@cebe.cc>
Date: Thu, 1 Mar 2018 00:20:31 +0100
Subject: [PATCH 6/7] Update main.tex

added unicode characters used in the guide
---
 templates/pdf/main.tex | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/templates/pdf/main.tex b/templates/pdf/main.tex
index d80e5c10..60f46cda 100644
--- a/templates/pdf/main.tex
+++ b/templates/pdf/main.tex
@@ -9,6 +9,8 @@
 % declare some unicode characters
 \DeclareUnicodeCharacter{2713}{yes} % ✓
 \DeclareUnicodeCharacter{20AC}{EUR} % €
+\DeclareUnicodeCharacter{251C}{|} % ├
+\DeclareUnicodeCharacter{2500}{-} % ─ 
 
 %
 % Title and author info

From 7490b987c1832edbe767d5e13a7c1ce0e22f23c4 Mon Sep 17 00:00:00 2001
From: Carsten Brandt <mail@cebe.cc>
Date: Thu, 1 Mar 2018 01:12:44 +0100
Subject: [PATCH 7/7] Update main.tex

---
 templates/pdf/main.tex | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/templates/pdf/main.tex b/templates/pdf/main.tex
index 60f46cda..f89416bf 100644
--- a/templates/pdf/main.tex
+++ b/templates/pdf/main.tex
@@ -10,7 +10,8 @@
 \DeclareUnicodeCharacter{2713}{yes} % ✓
 \DeclareUnicodeCharacter{20AC}{EUR} % €
 \DeclareUnicodeCharacter{251C}{|} % ├
-\DeclareUnicodeCharacter{2500}{-} % ─ 
+\DeclareUnicodeCharacter{2500}{-} % ─
+\DeclareUnicodeCharacter{2514}{|} % └
 
 %
 % Title and author info
