On gists
Nette - Neon - vlastní proměnné / own variables
•
Nette
Nette-Tricks
presenter.php
Raw
#
<?php
declare(strict_types = 1);
namespace Fp\Presenters;
use Fp\Template\TemplateHelpers;
use Nette\Application\UI\Presenter;
use Nette\Application\Helpers;
use Nette\Http\Url;
use Nette\Utils\Strings;
abstract class BasePresenter extends Presenter
{
/** @var string */
public $appDir;
/** @var string */
public $wwwDir;
/** @var bool */
public $productionMode;
/** @var string */
public $googleAnalyticsAccount;
/** @var string */
public $disqusShortname;
/** @var string */
public $twitterHandle;
/** @var string */
public $gplusAccountId;
/** @var string */
public $facebookUsername;
/** @var string */
public $facebookProfileId;
/** @var string */
public $githubRepository;
/** @var \Fp\FaviconsLoader @inject */
public $faviconsLoader;
protected function startup()
{
parent::startup();
if ($this->appDir === null) {
throw new \Exception('%appDir% was not provided');
}
}
protected function beforeRender()
{
parent::beforeRender();
$this->template->wwwDir = $this->wwwDir;
$this->template->productionMode = $this->productionMode;
$this->template->faviconMetas = $this->faviconsLoader->getMetadata();
$this->template->googleAnalyticsAccount = $this->googleAnalyticsAccount;
$this->template->disqusShortname = $this->disqusShortname;
$this->template->twitterHandle = $this->twitterHandle;
$this->template->gplusAccountId = $this->gplusAccountId;
$this->template->facebookUsername = $this->facebookUsername;
$this->template->facebookProfileId = $this->facebookProfileId;
$this->template->githubRepository = $this->githubRepository;
$this->template->now = new \DateTimeImmutable();
$canonicalUrlQuery = $this->getHttpRequest()->getUrl()->getQueryParameters();
foreach ($canonicalUrlQuery as $queryParameter => $_) {
if (Strings::startsWith($queryParameter, 'utm_')) {
unset($canonicalUrlQuery[$queryParameter]);
}
}
$this->template->canonicalUrl = (new Url($this->getHttpRequest()->getUrl()))->setQuery($canonicalUrlQuery);
}
protected function createTemplate()
{
/** @var \Nette\Bridges\ApplicationLatte\Template $template */
$template = parent::createTemplate();
$template->getLatte()->addFilter('filectime', 'filectime');
$template->getLatte()->addFilter('timeAgo', TemplateHelpers::class . '::timeAgoInWords');
return $template;
}
/**
* Formats layout template file names.
*
* @return string[]
*/
public function formatLayoutTemplateFiles(): array
{
if (is_string($this->layout) && preg_match('#/|\\\\#', $this->layout)) {
return [$this->layout];
}
return [
sprintf('%s/templates/@%s.latte', $this->appDir, $this->layout ?: 'layout'),
];
}
/**
* Formats view template file names.
*
* @return string[]
*/
public function formatTemplateFiles(): array
{
list(, $presenter) = Helpers::splitName($this->getName());
return [
sprintf('%s/templates/%s/%s.latte', $this->appDir, $presenter, $this->view),
];
}
}
config.neon
Raw
#
parameters:
varDir: %appDir%/../var
logDir: %varDir%/log
srcDir: %appDir%/../src
blogDir: %appDir%/../blog
googleAnalytics:
account: UA-12182518-9
disqus:
shortname: filip-prochazka-blog
twitter:
handle: ProchazkaFilip
gplus:
accountId: '103239456693574460264'
facebook:
username: FilipProchazka
profileId: '1634280910'
github:
repository: fprochazka/filip-prochazka.com
extensions:
monolog: Kdyby\Monolog\DI\MonologExtension
application:
errorPresenter: Error
mapping:
*: Fp\*Module\Presenters\*Presenter
scanDirs:
- %srcDir%/Presenters
di:
debugger: off
monolog:
handlers:
main: Monolog\Handler\StreamHandler("php://stderr")
session:
expiration: 14 days
autoStart: false
decorator:
Fp\Presenters\BasePresenter:
setup:
- $appDir(%appDir%)
- $wwwDir(%wwwDir%)
- $productionMode(%productionMode%)
- $googleAnalyticsAccount(%googleAnalytics.account%)
- $disqusShortname(%disqus.shortname%)
- $twitterHandle(%twitter.handle%)
- $gplusAccountId(%gplus.accountId%)
- $facebookUsername(%facebook.username%)
- $facebookProfileId(%facebook.profileId%)
- $githubRepository(%github.repository%)
includes:
- services.neon
- config.local.neon