Class yii\apidoc\templates\pdf\GuideRenderer

Inheritanceyii\apidoc\templates\pdf\GuideRenderer » yii\apidoc\templates\html\GuideRenderer » yii\apidoc\renderers\GuideRenderer » yii\apidoc\renderers\BaseRenderer » yii\base\Component
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-apidoc/blob/master/templates/pdf/GuideRenderer.php

Protected Methods

Hide inherited methods

Method Description Defined By
afterMarkdownProcess() Callback that is called after markdown is processed. yii\apidoc\templates\html\GuideRenderer
fixMarkdownLinks() Adds guide name to link URLs in markdown yii\apidoc\templates\html\GuideRenderer
generateGuideFileName() Given markdown file name generates resulting html file name yii\apidoc\templates\html\GuideRenderer
generateLink() Generate link markup yii\apidoc\templates\html\GuideRenderer
loadGuideStructure() Loads guide structure from a set of files yii\apidoc\renderers\GuideRenderer

Constants

Hide inherited constants

Constant Value Description Defined By
GUIDE_PREFIX 'guide-' Deprecated since 2.0.1 use $guidePrefix instead which allows configuring this options yii\apidoc\renderers\BaseRenderer

Method Details

Hide inherited methods

afterMarkdownProcess() protected method (available since version 2.0.5)

Defined in: yii\apidoc\templates\html\GuideRenderer::afterMarkdownProcess()

Callback that is called after markdown is processed.

You may override it to do some post processing. The default implementation fixes some markdown links using fixMarkdownLinks() on the output.

protected string afterMarkdownProcess ( $file, $output, $renderer )
$file string

The file that has been processed.

$output string

The rendered HTML output.

$renderer yii\apidoc\helpers\ApiMarkdown

The renderer instance.

                protected function afterMarkdownProcess($file, $output, $renderer)
{
    return $this->fixMarkdownLinks($output);
}

            
createSubjectLink() public method

Defined in: yii\apidoc\renderers\BaseRenderer::createSubjectLink()

Creates a link to a subject

public string createSubjectLink ( $subject, $title null, $options = [] )
$subject yii\apidoc\models\PropertyDoc|yii\apidoc\models\MethodDoc|yii\apidoc\models\ConstDoc|yii\apidoc\models\EventDoc
$title string
$options array

Additional HTML attributes for the link.

createTypeLink() public method

Defined in: yii\apidoc\renderers\BaseRenderer::createTypeLink()

Creates a link to a type (class, interface or trait)

public string createTypeLink ( $types, $context null, $title null, $options = [] )
$types yii\apidoc\models\ClassDoc|yii\apidoc\models\InterfaceDoc|yii\apidoc\models\TraitDoc|yii\apidoc\models\ClassDoc[]|yii\apidoc\models\InterfaceDoc[]|yii\apidoc\models\TraitDoc[]|string|string[]
$context yii\apidoc\models\BaseDoc
$title string

A title to be used for the link TODO check whether [[yii...|Class]] is supported

$options array

Additional HTML attributes for the link.

fixMarkdownLinks() protected method

Defined in: yii\apidoc\templates\html\GuideRenderer::fixMarkdownLinks()

Adds guide name to link URLs in markdown

protected string fixMarkdownLinks ( $content )
$content string

generateApiUrl() public method

Defined in: yii\apidoc\templates\html\GuideRenderer::generateApiUrl()

Generate an url to a type in apidocs

public mixed generateApiUrl ( $typeName )
$typeName

                public function generateApiUrl($typeName)
{
    return rtrim($this->apiUrl, '/') . '/' . strtolower(str_replace('\\', '-', $typeName)) . '.html';
}

            
generateGuideFileName() protected method

Defined in: yii\apidoc\templates\html\GuideRenderer::generateGuideFileName()

Given markdown file name generates resulting html file name

protected string generateGuideFileName ( $file )
$file string

Markdown file name

                protected function generateGuideFileName($file)
{
    return $this->guidePrefix . basename($file, '.md') . '.html';
}

            
generateGuideUrl() public method

Defined in: yii\apidoc\renderers\BaseRenderer::generateGuideUrl()

Generate an url to a guide page

public string generateGuideUrl ( $file )
$file string

                public function generateGuideUrl($file)
{
    //skip parsing external url
    if ( (strpos($file, 'https://') !== false) || (strpos($file, 'http://') !== false) ) {
        return $file;
    }
    $hash = '';
    if (($pos = strpos($file, '#')) !== false) {
        $hash = substr($file, $pos);
        $file = substr($file, 0, $pos);
    }
    return rtrim($this->guideUrl, '/') . '/' . $this->guidePrefix . basename($file, '.md') . '.html' . $hash;
}

            
generateLink() protected method
protected mixed generateLink ( $text, $href, $options = [] )
$text
$href
$options array

Additional HTML attributes for the link.

getGuideReferences() public method
public void getGuideReferences ( )

                public function getGuideReferences()
{
    // TODO implement for api docs
$refs = [];
foreach ($this->markDownFiles as $file) {
	$refName = 'guide-' . basename($file, '.md');
	$refs[$refName] = ['url' => $this->generateGuideFileName($file)];
}
return $refs;
}

            
getView() public method
public \yii\web\View getView ( )
return \yii\web\View

The view instance

                public function getView()
{
    if ($this->_view === null) {
        $this->_view = new View();
        $assetPath = Yii::getAlias($this->_targetDir) . '/assets';
        if (!is_dir($assetPath)) {
            mkdir($assetPath);
        }
        $this->_view->assetManager = new AssetManager([
            'basePath' => $assetPath,
            'baseUrl' => './assets',
        ]);
    }
    return $this->_view;
}

            
init() public method
public void init ( )

                public function init()
{
    parent::init();
    if ($this->pageTitle === null) {
        $this->pageTitle = 'The Definitive Guide to Yii 2.0';
    }
}

            
loadGuideStructure() protected method

Defined in: yii\apidoc\renderers\GuideRenderer::loadGuideStructure()

Loads guide structure from a set of files

protected array loadGuideStructure ( $files )
$files array

                protected function loadGuideStructure($files)
{
    $chapters = [];
    foreach ($files as $file) {
        $contents = file_get_contents($file);
        if (basename($file) == 'README.md') {
            $indexAnalyzer = new IndexFileAnalyzer();
            $chapters = $indexAnalyzer->analyze($contents);
            break;
        }
        if (preg_match("/^(.*)\n=+/", $contents, $matches)) {
            $headlines[$file] = $matches[1];
        } else {
            $headlines[$file] = basename($file);
        }
    }
    return $chapters;
}

            
render() public method

Renders a set of files given into target directory.

public void render ( $files, $targetDir )
$files array
$targetDir string

                public function render($files, $targetDir)
{
      $types = array_merge($this->apiContext->classes, $this->apiContext->interfaces, $this->apiContext->traits);
      $extTypes = [];
      foreach ($this->extensions as $k => $ext) {
          $extType = $this->filterTypes($types, $ext);
          if (empty($extType)) {
              unset($this->extensions[$k]);
              continue;
          }
          $extTypes[$ext] = $extType;
      }
    $fileCount = count($files) + 1;
    if ($this->controller !== null) {
        Console::startProgress(0, $fileCount, 'Rendering markdown files: ', false);
    }
    $done = 0;
    $fileData = [];
    $chapters = $this->loadGuideStructure($files);
    foreach ($files as $file) {
        $fileData[basename($file)] = file_get_contents($file);
          if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) {
              $headlines[$file] = $matches[1];
          } else {
              $headlines[$file] = basename($file);
          }
    }
    $md = new ApiMarkdownLaTeX();
    $output = '';
    foreach ($chapters as $chapter) {
        if (isset($chapter['headline'])) {
            $output .= '\chapter{' . $chapter['headline'] . "}\n";
        }
        foreach($chapter['content'] as $content) {
            // ignore URLs in TOC
            if (strpos($content['file'], 'http://') === 0 || strpos($content['file'], 'https://') === 0) {
                continue;
            }
            if (isset($fileData[$content['file']])) {
                $md->labelPrefix = $content['file'] . '#';
                $output .= '\label{'. $content['file'] . '}';
                $output .= $md->parse($fileData[$content['file']]) . "\n\n";
            } else {
                $output .= '\newpage';
                $output .= '\label{'. $content['file'] . '}';
                $output .= '\textbf{Error: not existing file: '.$content['file'].'}\newpage'."\n";
            }
            if ($this->controller !== null) {
                Console::updateProgress(++$done, $fileCount);
            }
        }
    }
    file_put_contents($targetDir . '/guide.tex', $output);
    copy(__DIR__ . '/main.tex', $targetDir . '/main.tex');
    copy(__DIR__ . '/title.tex', $targetDir . '/title.tex');
    copy(__DIR__ . '/Makefile', $targetDir . '/Makefile');
    if ($this->controller !== null) {
        Console::updateProgress(++$done, $fileCount);
        Console::endProgress(true);
        $this->controller->stdout('done.' . PHP_EOL, Console::FG_GREEN);
    }
    echo "\nnow run `make` in $targetDir (you need pdflatex to compile pdf file)\n\n";
}