Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit bfa8e57

Browse files
authored
Asset tag (#10)
* Fixed robots.txt * Refactored config; Added safeguards for languages/versions; Allow all languages * Work on the languages * Asset tag introduction and reformatting files
1 parent 8d5cd26 commit bfa8e57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+381
-280
lines changed

app/config/config.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
+------------------------------------------------------------------------+
1616
*/
1717

18+
use Docs\Controllers\DocsController;
1819
use function Docs\Functions\app_path;
1920
use function Docs\Functions\env;
20-
use Docs\Controllers\DocsController;
2121

2222
/**
2323
* Get the versions and languages
2424
*/
25-
$version = '0.1';
26-
$languages = [];
27-
$versions = [];
25+
$version = '0.1';
26+
$languages = [];
27+
$versions = [];
2828
$crowdinFile = app_path('/storage/crowdin/crowdin.json');
2929
if (true === file_exists($crowdinFile)) {
3030
$crowdin = file_get_contents($crowdinFile);
@@ -55,6 +55,7 @@
5555
'staticUrl' => env('APP_STATIC_URL'),
5656
'lang' => env('APP_LANG'),
5757
'supportEmail' => env('APP_SUPPORT_EMAIL'),
58+
'assetTag' => 'development' !== env('APP_ENV') ? env('ASSET_TAG') : time(),
5859
'googleAnalytics' => env('GOOGLE_ANALYTICS'),
5960
'algoliaSearchKey' => env('ALGOLIA_SEARCH_KEY'),
6061
],
@@ -64,16 +65,16 @@
6465
],
6566
'highlight' => [
6667
'version' => '9.11.0',
67-
'js' => [
68-
'cpp',
69-
'css',
70-
'json',
71-
'php',
72-
'shell',
73-
'twig',
74-
'yaml',
75-
'zephir',
76-
],
68+
'js' => [
69+
'cpp',
70+
'css',
71+
'json',
72+
'php',
73+
'shell',
74+
'twig',
75+
'yaml',
76+
'zephir',
77+
],
7778
],
7879
'providers' => [
7980
// Application Service Providers
@@ -91,7 +92,7 @@
9192
Docs\Providers\Dispatcher\ServiceProvider::class,
9293
Docs\Providers\Tags\ServiceProvider::class,
9394
],
94-
'routes' => [
95+
'routes' => [
9596
DocsController::class => [
9697
'methods' => [
9798
'get' => [

app/controllers/BaseController.php

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,15 @@
1717

1818
namespace Docs\Controllers;
1919

20-
use function array_search;
2120
use Phalcon\Cache\BackendInterface;
2221
use Phalcon\Config;
2322
use Phalcon\Mvc\Controller as PhController;
2423
use Phalcon\Mvc\View\Simple;
24+
use function array_search;
2525
use function Docs\Functions\app_path;
2626
use function Docs\Functions\config;
2727
use function Docs\Functions\environment;
2828
use function file_exists;
29-
use function var_dump;
3029

3130
/**
3231
* Docs\Controllers\BaseController
@@ -70,7 +69,7 @@ public function getSidebar($language, $version): array
7069

7170
if (true === file_exists($pageName)) {
7271
$data = file_get_contents($pageName);
73-
} elseif (true === file_exists($apiFileName)) {
72+
} else if (true === file_exists($apiFileName)) {
7473
$data = file_get_contents($apiFileName);
7574
} else {
7675
// The article does not exist
@@ -179,6 +178,25 @@ protected function getSeoTitle(string $language, string $version, string $page):
179178
return $title;
180179
}
181180

181+
/**
182+
* @param string $language
183+
* @param string $version
184+
* @param string $fileName
185+
*
186+
* @return string
187+
*/
188+
protected function getMenu($language, $version, $fileName): string
189+
{
190+
$document = $this->getDocument($language, $version, $fileName);
191+
$document = str_replace(
192+
'<li>',
193+
'<li class="toc-entry toc-h2">',
194+
$document
195+
);
196+
197+
return ltrim(rtrim($document, '</ul>'), '<ul>');
198+
}
199+
182200
/**
183201
* @param string $language
184202
* @param string $version
@@ -194,7 +212,7 @@ protected function getDocument($language, $version, $fileName): string
194212
return $this->cacheData->get($key);
195213
}
196214

197-
$pageName = app_path(
215+
$pageName = app_path(
198216
sprintf(
199217
'docs/%s/%s/%s.md',
200218
$version,
@@ -229,25 +247,6 @@ protected function getDocument($language, $version, $fileName): string
229247
return $data;
230248
}
231249

232-
/**
233-
* @param string $language
234-
* @param string $version
235-
* @param string $fileName
236-
*
237-
* @return string
238-
*/
239-
protected function getMenu($language, $version, $fileName): string
240-
{
241-
$document = $this->getDocument($language, $version, $fileName);
242-
$document = str_replace(
243-
'<li>',
244-
'<li class="toc-entry toc-h2">',
245-
$document
246-
);
247-
248-
return ltrim(rtrim($document, '</ul>'), '<ul>');
249-
}
250-
251250
/**
252251
* Returns the current version string with its prefix if applicable
253252
*

app/controllers/DocsController.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
namespace Docs\Controllers;
44

5-
use Docs\Cli\Tasks\GetLanguagesTask;
65
use Docs\Exception\HttpException;
76
use Phalcon\Http\ResponseInterface;
87
use Phalcon\Text;
98
use function Docs\Functions\base_url;
10-
use function str_replace;
119

1210
/**
1311
* Docs\Controllers\DocsController
@@ -63,13 +61,13 @@ public function mainAction(string $language = null, string $version = null, stri
6361
$contents = $this->viewSimple->render(
6462
$renderFile,
6563
[
66-
'page' => $page,
67-
'language' => $language,
68-
'version' => $version,
69-
'sidebar' => $this->getMenu($language, $version, 'sidebar'),
70-
'article' => $article,
71-
'menu' => $this->getMenu($language, $version, $page . '-menu'),
72-
'canonical' => $canonical,
64+
'page' => $page,
65+
'language' => $language,
66+
'version' => $version,
67+
'sidebar' => $this->getMenu($language, $version, 'sidebar'),
68+
'article' => $article,
69+
'menu' => $this->getMenu($language, $version, $page . '-menu'),
70+
'canonical' => $canonical,
7371
]
7472
);
7573
$this->response->setContent($contents);

app/library/Bootstrap.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public function __construct($mode = 'normal')
9797
/**
9898
* Initialize the Service Provider.
9999
*
100-
* Usually the Service Provider register a service in the Dependency Injector Container.
100+
* Usually the Service Provider register a service in the Dependency
101+
* Injector Container.
101102
*
102103
* @param ServiceProviderInterface $serviceProvider
103104
*
@@ -117,7 +118,8 @@ protected function initializeServiceProvider(ServiceProviderInterface $servicePr
117118
* If failed the `development` will be used.
118119
*
119120
* After getting `APP_ENV` variable we set the Bootstrap::$environment
120-
* and the `APPLICATION_ENV` constant which used in other Phalcon related projects eg Incubator.
121+
* and the `APPLICATION_ENV` constant which used in other Phalcon related
122+
* projects eg Incubator.
121123
*/
122124
protected function setupEnvironment()
123125
{
@@ -228,7 +230,8 @@ public function getApplication()
228230
}
229231

230232
/**
231-
* Gets current application environment: production, staging, development, testing, etc.
233+
* Gets current application environment: production, staging, development,
234+
* testing, etc.
232235
*
233236
* @return string
234237
*/

app/library/Exception/Handler/ErrorPageHandler.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace Docs\Exception\Handler;
1919

2020
use Whoops\Handler\Handler;
21-
use function Docs\Functions\config;
2221
use function Docs\Functions\container;
2322

2423
/**

app/library/Exception/Handler/LoggerHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function addTraceToOutput($addTraceToOutput = null)
136136
return $this->addTraceToOutput;
137137
}
138138

139-
$this->addTraceToOutput = (bool)$addTraceToOutput;
139+
$this->addTraceToOutput = (bool) $addTraceToOutput;
140140

141141
return $this;
142142
}
@@ -193,7 +193,7 @@ public function addTraceFunctionArgsToOutput($args = null)
193193
}
194194

195195
if (!is_integer($args)) {
196-
$this->addTraceFunctionArgsToOutput = (bool)$args;
196+
$this->addTraceFunctionArgsToOutput = (bool) $args;
197197
} else {
198198
$this->addTraceFunctionArgsToOutput = $args;
199199
}

app/providers/Assets/ServiceProvider.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,15 @@ function ($lang) {
8383
// TODO(o2)
8484
// ->addCss($cssCdn, false)
8585
->addCss(assets_uri('js/highlight/styles/googlecode.css', $version))
86-
->addCss(assets_uri('css/style.css', $version));
86+
->addCss(assets_uri('css/style.css', $version))
87+
;
8788

8889
$assets
8990
->collection('footer_js')
9091
// // TODO(o2)
9192
// ->addJs($jsCdn, false);
9293
->addJs(assets_uri('js/main.min.js', $version))
93-
->addJs(assets_uri('js/highlight/highlight.pack.js', $version));
94+
->addJs(assets_uri('js/highlight/highlight.pack.js', $version))
95+
;
9496
}
9597
}

app/providers/CacheData/ServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717

1818
namespace Docs\Providers\CacheData;
1919

20-
use function Docs\Functions\env;
2120
use Phalcon\Cache\Frontend\Data;
2221
use Phalcon\Di\ServiceProviderInterface;
2322
use Phalcon\DiInterface;
2423
use function Docs\Functions\app_path;
25-
use function Docs\Functions\config;
24+
use function Docs\Functions\env;
2625

2726
/**
2827
* Docs\Providers\CacheData\ServiceProvider

app/providers/Logger/ServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
namespace Docs\Providers\Logger;
1919

20-
use function Docs\Functions\env;
2120
use Phalcon\Di\ServiceProviderInterface;
2221
use Phalcon\DiInterface;
2322
use Phalcon\Logger;
2423
use Phalcon\Logger\Adapter\File;
2524
use Phalcon\Logger\Formatter\Line;
2625
use function Docs\Functions\app_path;
27-
use function Docs\Functions\config;
26+
use function Docs\Functions\env;
2827

2928
/**
3029
* Docs\Providers\Logger\ServiceProvider

app/providers/ViewCache/ServiceProvider.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Phalcon\Di\ServiceProviderInterface;
2222
use Phalcon\DiInterface;
2323
use function Docs\Functions\app_path;
24-
use function Docs\Functions\config;
2524

2625
/**
2726
* Docs\Providers\ViewCache\ServiceProvider
@@ -46,7 +45,7 @@ public function register(DiInterface $container)
4645
function () {
4746
$lifetime = env('CACHE_LIFETIME', 3600);
4847
$driver = env('VIEW_CACHE_DRIVER', 'file');
49-
$adapter = '\Phalcon\Cache\Backend\\' . ucfirst($driver);
48+
$adapter = '\Phalcon\Cache\Backend\\' . ucfirst($driver);
5049

5150
return new $adapter(
5251
new Output(['lifetime' => $lifetime]),

0 commit comments

Comments
 (0)