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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
16 deletions
+78
-16
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
+15
-15
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.
...
@@ -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
---------------------------
---------------------------
...
...
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;
...
@@ -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
=
[];
// $headline
s = [];
$chapter
s
=
[];
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,24 +64,21 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
...
@@ -61,24 +64,21 @@ 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
);
copy
(
__DIR__
.
'/main.tex'
,
$targetDir
.
'/main.tex'
);
copy
(
__DIR__
.
'/main.tex'
,
$targetDir
.
'/main.tex'
);
copy
(
__DIR__
.
'/Makefile'
,
$targetDir
.
'/Makefile'
);
copy
(
__DIR__
.
'/Makefile'
,
$targetDir
.
'/Makefile'
);
...
...
extensions/apidoc/templates/pdf/main.tex
View file @
66477091
\documentclass
[a4paper, 10pt]
{
article
}
\documentclass
[a4paper, 10pt]
{
book
}
% english and utf8
% 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