Renderer.php 1.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\apidoc\templates\online;
use yii\apidoc\models\Context;
use yii\apidoc\models\TypeDoc;
use yii\console\Controller;
use Yii;
use yii\helpers\Console;
use yii\helpers\FileHelper;
use yii\helpers\StringHelper;

/**
 *
 * @author Carsten Brandt <mail@cebe.cc>
 * @since 2.0
 */
class Renderer extends \yii\apidoc\templates\html\Renderer
{
24
	public $apiLayout = false;
25
	public $indexView = '@yii/apidoc/templates/online/views/index.php';
26 27 28 29 30 31 32 33 34

	public $pageTitle = 'Yii Framework 2.0 API Documentation';

	/**
	 * Renders a given [[Context]].
	 *
	 * @param Context $context the api documentation context to render.
	 * @param Controller $controller the apidoc controller instance. Can be used to control output.
	 */
35
	public function renderApi($context, $controller)
36
	{
37
		parent::renderApi($context, $controller);
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
		$dir = Yii::getAlias($this->targetDir);
		$controller->stdout("writing packages file...");
		$packages = [];
		$notNamespaced = [];
		foreach(array_merge($context->classes, $context->interfaces, $context->traits) as $type) {
			/** @var TypeDoc $type */
			if (empty($type->namespace)) {
				$notNamespaced[] = str_replace('\\', '-', $type->name);
			} else {
				$packages[$type->namespace][] = str_replace('\\', '-', $type->name);
			}
		}
		ksort($packages);
		$packages = array_merge(['Not namespaced' => $notNamespaced], $packages);
		foreach($packages as $name => $classes) {
			sort($packages[$name]);
		}
		file_put_contents($dir . '/packages.txt', serialize($packages));
		$controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
	}

59
	public function generateUrl($typeName)
60 61 62 63 64 65
	{
		return strtolower(str_replace('\\', '-', $typeName));
	}

	protected function generateFileName($typeName)
	{
66
		return $this->generateUrl($typeName) . '.html';
67 68
	}
}