GuideRenderer.php 1.55 KB
Newer Older
1 2 3 4 5 6 7 8
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\apidoc\templates\bootstrap;
Carsten Brandt committed
9

10
use Yii;
11 12 13
use yii\apidoc\helpers\ApiIndexer;
use yii\helpers\Console;
use yii\helpers\FileHelper;
14 15 16 17 18 19 20 21

/**
 *
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
 */
class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
{
22
    use RendererTrait;
23

24
    public $layout = '@yii/apidoc/templates/bootstrap/layouts/guide.php';
25

26

27 28 29 30 31 32
    /**
     * @inheritDoc
     */
    public function render($files, $targetDir)
    {
        $types = array_merge($this->apiContext->classes, $this->apiContext->interfaces, $this->apiContext->traits);
33

34 35 36 37 38 39 40 41 42
        $extTypes = [];
        foreach ($this->extensions as $k => $ext) {
            $extType = $this->filterTypes($types, $ext);
            if (empty($extType)) {
                unset($this->extensions[$k]);
                continue;
            }
            $extTypes[$ext] = $extType;
        }
43

44
        parent::render($files, $targetDir);
45 46 47 48 49 50 51 52 53 54 55 56 57

        if ($this->controller !== null) {
            $this->controller->stdout('generating search index...');
        }

        $indexer = new ApiIndexer();
        $indexer->indexFiles(FileHelper::findFiles($targetDir, ['only' => ['*.html']]), $targetDir);
        $js = $indexer->exportJs();
        file_put_contents($targetDir . '/jssearch.index.js', $js);

        if ($this->controller !== null) {
            $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
        }
58
    }
Luciano Baraglia committed
59
}