forked from Codeception/codeception.github.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoboFile.php
100 lines (85 loc) · 2.49 KB
/
RoboFile.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
100
<?php
use Symfony\Component\Finder\Finder;
class RoboFile extends \Robo\Tasks
{
function post()
{
$title = $this->ask("Post title");
$file = strtolower(str_replace([' ',':'], ['-','-'], $title));
$date = date('Y-m-d');
$this->taskWriteToFile("_posts/$date-$file.markdown")
->line('---')
->line('layout: post')
->line("title: \"$title\"")
->line("date: $date 01:03:50")
->line("---\n")
->run();
}
function publish()
{
$this->taskGitStack()
->add('-A')
->commit('updated')
->pull()
->push()
->run();
}
/**
* builds docs for specific branch
*/
function docsBranch($branch)
{
$this->yell("Creating docs for $branch");
$dir = "docs-$branch";
$this->taskGitStack()
->cloneRepo('[email protected]:Codeception/Codeception.git', 'source')
->run();
$this->taskGitStack()
->dir('source')
->checkout($branch)
->run();
$this->taskCleanDir($dir)->run();
$this->taskWriteToFile("_includes/doc_$branch.html")
->text('<div class="alert alert-danger">')
->text('You are viewing documentation for Codeception <strong>'.$branch.'</strong>. ')
->text('Switch to <a href="/docs">latest stable »</a>')
->text('</div>')
->run();
$indexFile = $this->taskWriteToFile($dir . '/index.md')
->line('---')
->line('layout: doc')
->line("title: Codeception $branch Documentation")
->line('---')
->text("\n\n{% include doc_$branch.html %}\n\n\n")
->line("# Codeception $branch Guides\n\n");
$guides = Finder::create()
->ignoreVCS(true)
->depth('== 0')
->name('*.md')
->sortByName()
->in('source/docs');
foreach ($guides as $file) {
$contents = file_get_contents($file->getRealPath());
$name = substr($file->getBasename(),0,-3);
$title = preg_replace("(\d+-)", '', $name);
if (preg_match('/^# (.*)$/m', $contents, $matches)) {
$title = $matches[1];
}
$indexFile->line("* [$title](/$dir/$name)");
$this->taskWriteToFile($dir . '/' . $file->getBasename())
->line('---')
->line('layout: doc')
->line('title: Codeception Documentation')
->line('---')
->line('')
->line('')
->text("{% include doc_$branch.html %}")
->line('')
->line('')
->text($contents)
->run();
}
$indexFile->run();
// $this->taskDeleteDir('source')->run();
}
}