Commit 66477091 by Carsten Brandt

generate PDF file chapters from README.md structure

parent d52299ba
...@@ -59,6 +59,19 @@ Currently there is only the `bootstrap` template available. ...@@ -59,6 +59,19 @@ Currently there is only the `bootstrap` template available.
You may also add the `yii\apidoc\commands\RenderController` to your console application class map and You may also add the `yii\apidoc\commands\RenderController` to your console application class map and
run it inside of your applications console app. run it inside of your applications console app.
Creating a PDF from the guide
-----------------------------
You need `pdflatex` and `make` for this.
```
vendor/bin/apidoc guide source/docs ./output --template=pdf
cd ./output
make pdf
```
If all runs without errors the PDF will be `guide.pdf` in the `output` dir.
Creating your own templates Creating your own templates
--------------------------- ---------------------------
......
<?php
/**
* Created by PhpStorm.
* User: cebe
* Date: 26.05.14
* Time: 18:15
*/
namespace yii\apidoc\helpers;
use cebe\markdown\Markdown;
class IndexFileAnalyzer extends Markdown
{
private $_chapter = 0;
private $_chapters = [];
public function analyze($text)
{
$this->parse($text);
return $this->_chapters;
}
protected function renderHeadline($block)
{
$this->_chapters[++$this->_chapter] = [
'headline' => $block['content'],
'content' => [],
];
return parent::renderHeadline($block);
}
protected function renderList($block)
{
foreach ($block['items'] as $item => $itemLines) {
if (preg_match('~\[([^\]]+)\]\(([^\)]+)\)(.*)~', implode("\n", $itemLines), $matches)) {
$this->_chapters[$this->_chapter]['content'][] = [
'headline' => $matches[1],
'file' => $matches[2],
'teaser' => $matches[3],
];
}
}
return parent::renderList($block);
}
}
\ No newline at end of file
...@@ -10,6 +10,7 @@ namespace yii\apidoc\templates\pdf; ...@@ -10,6 +10,7 @@ namespace yii\apidoc\templates\pdf;
use cebe\markdown\latex\GithubMarkdown; use cebe\markdown\latex\GithubMarkdown;
use Yii; use Yii;
use yii\apidoc\helpers\ApiIndexer; use yii\apidoc\helpers\ApiIndexer;
use yii\apidoc\helpers\IndexFileAnalyzer;
use yii\helpers\Console; use yii\helpers\Console;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
...@@ -43,15 +44,17 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer ...@@ -43,15 +44,17 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
} }
$done = 0; $done = 0;
$fileData = []; $fileData = [];
// $headlines = []; $chapters = [];
foreach ($files as $file) { foreach ($files as $file) {
if (basename($file) == 'README.md') { if (basename($file) == 'README.md') {
$indexAnalyzer = new IndexFileAnalyzer();
$chapters = $indexAnalyzer->analyze(file_get_contents($file));
continue; // to not add index file to nav continue; // to not add index file to nav
} }
if (basename($file) == 'tutorial-i18n.md') { if (basename($file) == 'tutorial-i18n.md') {
continue; // TODO avoid i18n tut because of non displayable characters right now. need to fix it. continue; // TODO avoid i18n tut because of non displayable characters right now. need to fix it.
} }
$fileData[$file] = file_get_contents($file); $fileData[basename($file)] = file_get_contents($file);
// if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) { // if (preg_match("/^(.*)\n=+/", $fileData[$file], $matches)) {
// $headlines[$file] = $matches[1]; // $headlines[$file] = $matches[1];
// } else { // } else {
...@@ -61,22 +64,19 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer ...@@ -61,22 +64,19 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
$md = new GithubMarkdown(); $md = new GithubMarkdown();
$output = ''; $output = '';
foreach ($fileData as $file => $content) { foreach ($chapters as $chapter) {
$output .= $md->parse($content) . "\n\n"; // TODO generate links to yiiframework.com by default
// $output = $this->fixMarkdownLinks($output); $output .= '\chapter{' . $chapter['headline'] . "}\n";
// if ($this->layout !== false) { foreach($chapter['content'] as $content) {
// $params = [ if (isset($fileData[$content['file']])) {
//// 'headlines' => $headlines, $output .= $md->parse($fileData[$content['file']]) . "\n\n";
// 'currentFile' => $file, } else {
// 'content' => $output, $output .= '\newpage\textbf{Error: not existing file: '.$content['file'].'}\newpage'."\n";
// ]; }
// $output = $this->getView()->renderFile($this->layout, $params, $this);
// }
// $fileName = $this->generateGuideFileName($file);
// file_put_contents($targetDir . '/' . $fileName, $output);
if ($this->controller !== null) { if ($this->controller !== null) {
Console::updateProgress(++$done, $fileCount); Console::updateProgress(++$done, $fileCount);
}
} }
} }
file_put_contents($targetDir . '/guide.tex', $output); file_put_contents($targetDir . '/guide.tex', $output);
......
\documentclass[a4paper, 10pt]{article} \documentclass[a4paper, 10pt]{book}
% english and utf8 % english and utf8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment