Skip to content

Commit ae038c3

Browse files
committed
Fix templates
1 parent de1d4c2 commit ae038c3

File tree

13 files changed

+111
-116
lines changed

13 files changed

+111
-116
lines changed

.php-cs-fixer.dist.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
use PhpCsFixer\Finder;
77
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
88

9-
$finder = (new Finder())->in([
10-
__DIR__ . '/commands',
11-
__DIR__ . '/components',
12-
__DIR__ . '/helpers',
13-
__DIR__ . '/models',
14-
__DIR__ . '/renderers',
15-
__DIR__ . '/tests',
16-
]);
9+
$finder = (new Finder())
10+
->in([
11+
__DIR__ . '/commands',
12+
__DIR__ . '/components',
13+
__DIR__ . '/helpers',
14+
__DIR__ . '/models',
15+
__DIR__ . '/renderers',
16+
__DIR__ . '/templates',
17+
__DIR__ . '/tests',
18+
])->notPath([
19+
// PHP CS Fixer doesn't work well with view, so we exclude it
20+
'#views#',
21+
'#layouts#',
22+
]);
1723

1824
return (new Config())
1925
->setParallelConfig(ParallelConfigFactory::detect())

templates/bootstrap/ApiRenderer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -7,7 +8,6 @@
78

89
namespace yii\apidoc\templates\bootstrap;
910

10-
use Yii;
1111
use yii\apidoc\helpers\ApiIndexer;
1212
use yii\helpers\Console;
1313
use yii\helpers\FileHelper;
@@ -24,7 +24,6 @@ class ApiRenderer extends \yii\apidoc\templates\html\ApiRenderer
2424
public $layout = '@yii/apidoc/templates/bootstrap/layouts/api.php';
2525
public $indexView = '@yii/apidoc/templates/bootstrap/views/index.php';
2626

27-
2827
/**
2928
* @inheritdoc
3029
*/

templates/bootstrap/GuideRenderer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -7,7 +8,6 @@
78

89
namespace yii\apidoc\templates\bootstrap;
910

10-
use Yii;
1111
use yii\apidoc\helpers\ApiIndexer;
1212
use yii\helpers\Console;
1313
use yii\helpers\FileHelper;
@@ -23,7 +23,6 @@ class GuideRenderer extends \yii\apidoc\templates\html\GuideRenderer
2323

2424
public $layout = '@yii/apidoc/templates/bootstrap/layouts/guide.php';
2525

26-
2726
/**
2827
* @inheritDoc
2928
*/

templates/bootstrap/RendererTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -39,7 +40,6 @@ trait RendererTrait
3940
'twig',
4041
];
4142

42-
4343
/**
4444
* Returns nav TypeDocs
4545
* @param TypeDoc|null $type typedoc to take category from

templates/bootstrap/SideNavWidget.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -7,7 +8,6 @@
78

89
namespace yii\apidoc\templates\bootstrap;
910

10-
use Yii;
1111
use yii\base\InvalidConfigException;
1212
use yii\bootstrap\BootstrapAsset;
1313
use yii\bootstrap\Widget;
@@ -79,7 +79,6 @@ class SideNavWidget extends Widget
7979
*/
8080
public $activeUrl;
8181

82-
8382
/**
8483
* Initializes the widget.
8584
*/
@@ -166,8 +165,8 @@ public function renderItem($item, $collapsed = true)
166165
'encodeLabels' => $this->encodeLabels,
167166
'view' => $this->getView(),
168167
'options' => [
169-
'class' => "submenu panel-collapse collapse" . ($active || !$collapsed ? ' in' : '')
170-
]
168+
'class' => "submenu panel-collapse collapse" . ($active || !$collapsed ? ' in' : ''),
169+
],
171170
]);
172171
}
173172
}

templates/bootstrap/assets/AssetBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC

templates/bootstrap/assets/HighlightBundle.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -7,8 +8,6 @@
78

89
namespace yii\apidoc\templates\bootstrap\assets;
910

10-
use yii\web\View;
11-
1211
/**
1312
* The asset bundle for the highlight.js styles.
1413
*
@@ -19,6 +18,6 @@ class HighlightBundle extends \yii\web\AssetBundle
1918
{
2019
public $sourcePath = '@vendor/scrivo/highlight.php/styles';
2120
public $css = [
22-
'solarized-light.css'
21+
'solarized-light.css',
2322
];
2423
}

templates/bootstrap/assets/JsSearchAsset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC

templates/html/ApiRenderer.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -62,7 +63,6 @@ class ApiRenderer extends BaseApiRenderer implements ViewContextInterface
6263
*/
6364
private $_targetDir;
6465

65-
6666
/**
6767
* @inheritdoc
6868
*/
@@ -114,7 +114,7 @@ public function render($context, $targetDir)
114114
}
115115

116116
$done = 0;
117-
$higlighter = new Highlighter;
117+
$higlighter = new Highlighter();
118118

119119
foreach ($types as $type) {
120120
$fileContent = $this->renderWithLayout($this->typeView, [
@@ -139,23 +139,6 @@ public function render($context, $targetDir)
139139
}
140140
}
141141

142-
/**
143-
* Renders file applying layout
144-
* @param string $viewFile the view name
145-
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
146-
* @return string
147-
*/
148-
protected function renderWithLayout($viewFile, $params)
149-
{
150-
$output = $this->getView()->render($viewFile, $params, $this);
151-
if ($this->layout !== false) {
152-
$params['content'] = $output;
153-
return $this->getView()->renderFile($this->layout, $params, $this);
154-
}
155-
156-
return $output;
157-
}
158-
159142
/**
160143
* @param ClassDoc $class
161144
* @return string
@@ -274,7 +257,7 @@ public function renderMethodSignature(MethodDoc $method, ?TypeDoc $context = nul
274257
. ApiMarkdown::highlight(
275258
$param->name
276259
. ($param->isOptional ? ' = ' . $this->renderDefaultValue($param->defaultValue) : ''),
277-
'php'
260+
'php',
278261
);
279262
}
280263

@@ -335,38 +318,55 @@ public function generateApiUrl($typeName)
335318
}
336319

337320
/**
338-
* Generates file name for API page for a given type
339-
* @param string $typeName
340-
* @return string
321+
* @inheritdoc
341322
*/
342-
protected function generateFileName($typeName)
323+
public function getViewPath()
343324
{
344-
return strtolower(str_replace('\\', '-', $typeName)) . '.html';
325+
return Yii::getAlias('@yii/apidoc/templates/html/views');
345326
}
346327

347328
/**
348329
* @inheritdoc
349330
*/
350-
public function getViewPath()
331+
public function getSourceUrl($type, $line = null)
351332
{
352-
return Yii::getAlias('@yii/apidoc/templates/html/views');
333+
return null;
353334
}
354335

355336
/**
356-
* @inheritdoc
337+
* Renders file applying layout
338+
* @param string $viewFile the view name
339+
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
340+
* @return string
357341
*/
358-
protected function generateLink($text, $href, $options = [])
342+
protected function renderWithLayout($viewFile, $params)
359343
{
360-
$options['href'] = $href;
344+
$output = $this->getView()->render($viewFile, $params, $this);
345+
if ($this->layout !== false) {
346+
$params['content'] = $output;
347+
return $this->getView()->renderFile($this->layout, $params, $this);
348+
}
361349

362-
return Html::a($text, null, $options);
350+
return $output;
351+
}
352+
353+
/**
354+
* Generates file name for API page for a given type
355+
* @param string $typeName
356+
* @return string
357+
*/
358+
protected function generateFileName($typeName)
359+
{
360+
return strtolower(str_replace('\\', '-', $typeName)) . '.html';
363361
}
364362

365363
/**
366364
* @inheritdoc
367365
*/
368-
public function getSourceUrl($type, $line = null)
366+
protected function generateLink($text, $href, $options = [])
369367
{
370-
return null;
368+
$options['href'] = $href;
369+
370+
return Html::a($text, null, $options);
371371
}
372372
}

templates/html/GuideRenderer.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @link https://www.yiiframework.com/
45
* @copyright Copyright (c) 2008 Yii Software LLC
@@ -38,7 +39,6 @@ abstract class GuideRenderer extends BaseGuideRenderer
3839
*/
3940
private $_targetDir;
4041

41-
4242
/**
4343
* @inheritdoc
4444
*/
@@ -120,6 +120,25 @@ public function render($files, $targetDir)
120120
}
121121
}
122122

123+
public function getGuideReferences()
124+
{
125+
// TODO implement for api docs
126+
// $refs = [];
127+
// foreach ($this->markDownFiles as $file) {
128+
// $refName = 'guide-' . basename($file, '.md');
129+
// $refs[$refName] = ['url' => $this->generateGuideFileName($file)];
130+
// }
131+
// return $refs;
132+
}
133+
134+
/**
135+
* @inheritdoc
136+
*/
137+
public function generateApiUrl($typeName)
138+
{
139+
return rtrim($this->apiUrl, '/') . '/' . strtolower(str_replace('\\', '-', $typeName)) . '.html';
140+
}
141+
123142
/**
124143
* Callback that is called after markdown is processed.
125144
*
@@ -147,17 +166,6 @@ protected function generateGuideFileName($file)
147166
return $this->guidePrefix . basename($file, '.md') . '.html';
148167
}
149168

150-
public function getGuideReferences()
151-
{
152-
// TODO implement for api docs
153-
// $refs = [];
154-
// foreach ($this->markDownFiles as $file) {
155-
// $refName = 'guide-' . basename($file, '.md');
156-
// $refs[$refName] = ['url' => $this->generateGuideFileName($file)];
157-
// }
158-
// return $refs;
159-
}
160-
161169
/**
162170
* Adds guide name to link URLs in markdown
163171
* @param string $content
@@ -191,12 +199,4 @@ protected function generateLink($text, $href, $options = [])
191199

192200
return Html::a($text, null, $options);
193201
}
194-
195-
/**
196-
* @inheritdoc
197-
*/
198-
public function generateApiUrl($typeName)
199-
{
200-
return rtrim($this->apiUrl, '/') . '/' . strtolower(str_replace('\\', '-', $typeName)) . '.html';
201-
}
202202
}

0 commit comments

Comments
 (0)