|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* Task runner, code generator and build tool for easier continuos integration |
|
5
|
|
|
* |
|
6
|
|
|
* @link https://github.com/hiqdev/hidev |
|
7
|
|
|
* @package hidev |
|
8
|
|
|
* @license BSD-3-Clause |
|
9
|
|
|
* @copyright Copyright (c) 2014-2015, HiQDev (http://hiqdev.com/) |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace hidev\goals; |
|
13
|
|
|
|
|
14
|
|
|
use hidev\helpers\Helper; |
|
15
|
|
|
use Yii; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Goal for README. |
|
19
|
|
|
*/ |
|
20
|
|
|
class ReadmeGoal extends TemplateGoal |
|
21
|
|
|
{ |
|
22
|
|
|
public function getTemplate() |
|
23
|
|
|
{ |
|
24
|
|
|
return 'README'; |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function renderH($title, $char) |
|
28
|
|
|
{ |
|
29
|
|
|
$res = $title . "\n"; |
|
30
|
|
|
$res .= str_repeat($char, mb_strlen($title, Yii::$app->charset)); |
|
31
|
|
|
|
|
32
|
|
|
return $res . "\n"; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function renderH1($title) |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->renderH($title, '='); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function renderH2($title) |
|
41
|
|
|
{ |
|
42
|
|
|
return $this->renderH($title, '-'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function renderText($text) |
|
46
|
|
|
{ |
|
47
|
|
|
$text = trim($text); |
|
48
|
|
|
|
|
49
|
|
|
return $text ? "\n$text\n" : ''; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function renderBold($text) |
|
53
|
|
|
{ |
|
54
|
|
|
$text = trim($text); |
|
55
|
|
|
|
|
56
|
|
|
return $this->renderText('**' . $text . '**'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function renderSection($section, $default = null) |
|
60
|
|
|
{ |
|
61
|
|
|
$file = 'readme/' . str_replace(' ', '', $section); |
|
62
|
|
|
$path = Yii::getAlias("@source/docs/$file.md"); |
|
63
|
|
|
$text = file_exists($path) ? file_get_contents($path) : $this->getSection($file, $default); |
|
64
|
|
|
$text = trim($text); |
|
65
|
|
|
|
|
66
|
|
|
return $text ? "\n## $section\n\n$text\n" : ''; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getSection($file, $default = null) |
|
70
|
|
|
{ |
|
71
|
|
|
$view = Yii::$app->getView(); |
|
72
|
|
|
$tpl = Helper::file2template($file); |
|
73
|
|
|
|
|
74
|
|
|
return $view->existsTemplate($tpl) ? $view->render($tpl, ['config' => $this->config]) : $default; |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function getSections() |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->getItem('sections') ?: ['Requirements', 'Installation', 'Configuration', 'Basic Usage', 'Usage', 'Support', 'License', 'Acknowledgments']; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function renderSections($sections = null) |
|
83
|
|
|
{ |
|
84
|
|
|
if ($sections === null) { |
|
85
|
|
|
$sections = $this->sections; |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
$res = ''; |
|
88
|
|
|
foreach ($sections as $section) { |
|
89
|
|
|
$res .= $this->renderSection($section); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
return $res; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public $known_badges = [ |
|
96
|
|
|
'github.version' => '[](https://badge.fury.io/gh/{{ config.vendor.name }}%2F{{ config.package.name }})', |
|
97
|
|
|
'packagist.stable' => '[](//packagist.org/packages/{{ config.composer.fullName }})', |
|
98
|
|
|
'packagist.unstable' => '[](//packagist.org/packages/{{ config.composer.fullName }})', |
|
99
|
|
|
'packagist.license' => '[](//packagist.org/packages/{{ config.composer.fullName }})', |
|
100
|
|
|
'packagist.downloads' => '[](//packagist.org/packages/{{ config.composer.fullName }})', |
|
101
|
|
|
'versioneye.dependencies' => '[](https://www.versioneye.com/php/{{ config.vendor.name }}:{{ config.package.name }}/dev-master)', |
|
102
|
|
|
'travisci.build' => '[](http://travis-ci.org/{{ config.package.fullName }})', |
|
103
|
|
|
]; |
|
104
|
|
|
|
|
105
|
|
|
public function renderBadges() |
|
106
|
|
|
{ |
|
107
|
|
|
$badges = $this->badges; |
|
|
|
|
|
|
108
|
|
|
if (!$badges) { |
|
109
|
|
|
return ''; |
|
110
|
|
|
} |
|
111
|
|
|
if (!$this->package->getPackageManager()->getConfigFile()->getRequire()) { |
|
|
|
|
|
|
112
|
|
|
unset($badges['versioneye.dependencies']); |
|
113
|
|
|
} |
|
114
|
|
|
$res = ''; |
|
115
|
|
|
foreach ($badges as $badge => $tpl) { |
|
116
|
|
|
if (!$tpl) { |
|
117
|
|
|
$tpl = $this->known_badges[$badge]; |
|
118
|
|
|
} |
|
119
|
|
|
if ($tpl === 'disabled') { |
|
120
|
|
|
continue; |
|
121
|
|
|
} |
|
122
|
|
|
$res .= $this->renderBadge($tpl) . "\n"; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
return $res ? "\n$res" : ''; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function renderBadge($tpl) |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->getTwig()->render($tpl, ['config' => $this->getConfig()]); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
protected $_twig; |
|
134
|
|
|
|
|
135
|
|
|
public function getTwig() |
|
136
|
|
|
{ |
|
137
|
|
|
if ($this->_twig === null) { |
|
138
|
|
|
$this->_twig = new \Twig_Environment(new \Twig_Loader_String()); |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return $this->_twig; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.