-
Notifications
You must be signed in to change notification settings - Fork 15
/
doctum.php
99 lines (86 loc) · 3.27 KB
/
doctum.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
98
99
<?php
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use Doctum\Project;
use Doctum\Doctum;
use SilverStripe\ApiDocs\Data\ApiJsonStore;
use SilverStripe\ApiDocs\Data\Config;
use SilverStripe\ApiDocs\Inspections\RecipeFinder;
use SilverStripe\ApiDocs\Inspections\RecipeVersionCollection;
use SilverStripe\ApiDocs\RemoteRepository\SilverStripeRemoteRepository;
// Get config
$config = Config::getConfig();
// Build versions
/** @var RecipeVersionCollection $versions */
$versions = new RecipeVersionCollection();
foreach ($config['versions'] as $version => $description) {
$versions->add((string)$version, $description);
}
// Build finder which draws from the recipe collection
$iterator = new RecipeFinder($versions);
$iterator
->files()
->name('*.php')
->exclude('thirdparty')
->exclude('examples')
->exclude('tests');
// Config
$doctum = new Doctum($iterator, [
'theme' => $config['theme'],
'title' => $config['title'],
'base_url' => $config['base_url'],
'versions' => $versions,
'build_dir' => Config::configPath($config['paths']['www']) . '/%version%',
'cache_dir' => Config::configPath($config['paths']['cache']) . '/%version%',
'source_dir' => $versions->getPackagePath(''),// Root of all the packages
'remote_repository' => new SilverStripeRemoteRepository('', $versions->getPackagePath('') . '/'),
'template_dirs' => [ __DIR__ .'/themes' ],
'base_url' => 'https://api.silverstripe.org/%version%/',
]);
// Make sure we document `@config` options
$doctum['filter'] = function() {
return new \SilverStripe\ApiDocs\Parser\Filter\SilverStripeFilter();
};
$doctum['php_traverser'] = function ($sc) {
$traverser = new NodeTraverser();
$traverser->addVisitor(new NameResolver());
$traverser->addVisitor(new \SilverStripe\ApiDocs\Parser\SilverStripeNodeVisitor($sc['parser_context']));
return $traverser;
};
$doctum['renderer'] = function ($sc) {
return new \SilverStripe\ApiDocs\Renderer\SilverStripeRenderer($sc['twig'], $sc['themes'], $sc['tree'], $sc['indexer']);
};
// Override json store
$store = $doctum['store'];
unset($doctum['store']);
$doctum['store'] = function () {
return new ApiJsonStore();
};
// Override project
unset($doctum['project']);
$doctum['project'] = function ($sc) {
$project = new Project($sc['store'], $sc['_versions'], array(
'build_dir' => $sc['build_dir'],
'cache_dir' => $sc['cache_dir'],
'remote_repository' => $sc['remote_repository'],
'include_parent_data' => $sc['include_parent_data'],
'default_opened_level' => $sc['default_opened_level'],
'theme' => $sc['theme'],
'title' => $sc['title'],
'source_url' => $sc['source_url'],
'source_dir' => $sc['source_dir'],
'insert_todos' => $sc['insert_todos'],
'base_url' => $sc['base_url'],
'footer_link' => [
'href' => 'https://github.com/silverstripe/api.silverstripe.org',
'rel' => 'noreferrer noopener',
'target' => '_blank',
'before_text' => 'Contributions to this documentation repository are welcomed',
'link_text' => 'on Github!',
],
));
$project->setRenderer($sc['renderer']);
$project->setParser($sc['parser']);
return $project;
};
return $doctum;