Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
66477091
Commit
66477091
authored
May 26, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
generate PDF file chapters from README.md structure
parent
d52299ba
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
18 deletions
+80
-18
README.md
extensions/apidoc/README.md
+13
-0
IndexFileAnalyzer.php
extensions/apidoc/helpers/IndexFileAnalyzer.php
+49
-0
GuideRenderer.php
extensions/apidoc/templates/pdf/GuideRenderer.php
+17
-17
main.tex
extensions/apidoc/templates/pdf/main.tex
+1
-1
No files found.
extensions/apidoc/README.md
View file @
66477091
...
...
@@ -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
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
---------------------------
...
...
extensions/apidoc/helpers/IndexFileAnalyzer.php
0 → 100644
View file @
66477091
<?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
extensions/apidoc/templates/pdf/GuideRenderer.php
View file @
66477091
...
...
@@ -10,6 +10,7 @@ namespace yii\apidoc\templates\pdf;
use
cebe\markdown\latex\GithubMarkdown
;
use
Yii
;
use
yii\apidoc\helpers\ApiIndexer
;
use
yii\apidoc\helpers\IndexFileAnalyzer
;
use
yii\helpers\Console
;
use
yii\helpers\FileHelper
;
...
...
@@ -43,15 +44,17 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
}
$done
=
0
;
$fileData
=
[];
// $headline
s = [];
$chapter
s
=
[];
foreach
(
$files
as
$file
)
{
if
(
basename
(
$file
)
==
'README.md'
)
{
$indexAnalyzer
=
new
IndexFileAnalyzer
();
$chapters
=
$indexAnalyzer
->
analyze
(
file_get_contents
(
$file
));
continue
;
// to not add index file to nav
}
if
(
basename
(
$file
)
==
'tutorial-i18n.md'
)
{
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)) {
// $headlines[$file] = $matches[1];
// } else {
...
...
@@ -61,22 +64,19 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
$md
=
new
GithubMarkdown
();
$output
=
''
;
foreach
(
$fileData
as
$file
=>
$content
)
{
$output
.=
$md
->
parse
(
$content
)
.
"
\n\n
"
;
// TODO generate links to yiiframework.com by default
// $output = $this->fixMarkdownLinks($output);
// if ($this->layout !== false) {
// $params = [
//// 'headlines' => $headlines,
// 'currentFile' => $file,
// 'content' => $output,
// ];
// $output = $this->getView()->renderFile($this->layout, $params, $this);
// }
// $fileName = $this->generateGuideFileName($file);
// file_put_contents($targetDir . '/' . $fileName, $output);
foreach
(
$chapters
as
$chapter
)
{
$output
.=
'\chapter{'
.
$chapter
[
'headline'
]
.
"}
\n
"
;
foreach
(
$chapter
[
'content'
]
as
$content
)
{
if
(
isset
(
$fileData
[
$content
[
'file'
]]))
{
$output
.=
$md
->
parse
(
$fileData
[
$content
[
'file'
]])
.
"
\n\n
"
;
}
else
{
$output
.=
'\newpage\textbf{Error: not existing file: '
.
$content
[
'file'
]
.
'}\newpage'
.
"
\n
"
;
}
if
(
$this
->
controller
!==
null
)
{
Console
::
updateProgress
(
++
$done
,
$fileCount
);
if
(
$this
->
controller
!==
null
)
{
Console
::
updateProgress
(
++
$done
,
$fileCount
);
}
}
}
file_put_contents
(
$targetDir
.
'/guide.tex'
,
$output
);
...
...
extensions/apidoc/templates/pdf/main.tex
View file @
66477091
\documentclass
[a4paper, 10pt]
{
article
}
\documentclass
[a4paper, 10pt]
{
book
}
% english and utf8
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment