-
Notifications
You must be signed in to change notification settings - Fork 0
/
readme.php
executable file
·97 lines (89 loc) · 4.1 KB
/
readme.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
use Premier\MarkdownBuilder\Block\Builder;
use Premier\MarkdownBuilder\Markdown;
require_once \dirname(__DIR__).'/vendor/autoload.php';
$codeAndMarkdownCallback = static function (Builder $builder, string $code): void {
$builder
->code(''.\trim($code), 'php')
->code(eval('use Premier\MarkdownBuilder\Markdown; use Premier\MarkdownBuilder\Block\{Builder, TableBuilder, BulletedListBuilder, NumberedListBuilder, ChecklistBuilder}; return (string) '.$code), 'markdown')
;
};
$parseFileCallback = static function (Builder $builder, string $file) use ($codeAndMarkdownCallback): void {
$codeAndMarkdownCallback($builder, \file_get_contents(\dirname(__DIR__).'/docs/'.$file));
};
$parseDirCallback = static function (Builder $builder, string $dir) use ($codeAndMarkdownCallback): void {
foreach (\scandir($dir) as $file) {
if (\in_array($file, ['.', '..'], true)) {
continue;
}
$builder
->h4(\substr(\str_replace('_', ' ', $file), 4))
->callback($codeAndMarkdownCallback, \file_get_contents($dir.'/'.$file))
;
}
};
Markdown::builder()
->inline(static function (Builder $builder): void {
$builder
->badge(
'Latest Stable Version',
'https://poser.pugx.org/premier/markdown-builder/v',
'//packagist.org/packages/premier/markdown-builder',
)
->badge(
'Total Downloads',
'https://poser.pugx.org/premier/markdown-builder/downloads',
'//packagist.org/packages/premier/markdown-builder',
)
->badge(
'Dependents',
'https://poser.pugx.org/premier/markdown-builder/dependents',
'//packagist.org/packages/premier/markdown-builder',
)
->badge(
'License',
'https://poser.pugx.org/premier/markdown-builder/license',
'//packagist.org/packages/premier/markdown-builder',
)
->badge(
'codecov',
'https://codecov.io/gh/grachevko/markdown-builder/branch/main/graph/badge.svg?token=W5FVJRFL6T',
'https://codecov.io/gh/grachevko/markdown-builder',
)
->badge(
'Mutation testing badge',
'https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fgrachevko%2Fmarkdown-builder%2Fmain',
'https://dashboard.stryker-mutator.io/reports/github.com/grachevko/markdown-builder/main',
)
;
})
->h1('Markdown Builder')
->p('A helper class to create markdown.')
->p('This README.md generated by this library, check '.Markdown::link('bin/readme.php', 'bin/readme.php').' for details.')
->h2('Installation')
->code('composer require premier/markdown-builder', 'bash')
->h2('Usage')
->callback($parseFileCallback, 'usage')
->h1('API')
->p(<<<'TEXT'
The markdown builder have two kinds of elements, block and inline elements.
Block elements will be buffered and you can get the markdown if you call the method `getMarkdown()`.
All inline Elements get instantly the markdown output.
TEXT)
->h3('Block Elements')
->callback($parseDirCallback, \dirname(__DIR__).'/docs/blocks')
->h3('Inline Blocks')
->callback($parseDirCallback, \dirname(__DIR__).'/docs/inline')
->h3('Advanced Features')
->h4('Collapse block')
->p('if you need collapse blocks, you can create a new builder instance with his own clean buffer.')
->callback($parseFileCallback, 'collapse')
->h4('Callback')
->p('If you want to add blocks from complex logic or iterable value, but don\'t want to stop chain calls you can use callback.')
->callback($parseFileCallback, 'callback')
->h4('Dump to File')
->p('Instead of returning markdown as a string you can easy dump result to file.')
->code('Markdown::builder()->h1(\'Hello world!\')->dump(\'index.md\');', 'php')
->dump(\dirname(__DIR__).'/README.md')
;