15 Commits
0.1.1 ... 0.2.0

22 changed files with 682 additions and 492 deletions

View File

@@ -11,7 +11,6 @@ Dossier requires PHP 7.2+ and the following extensions enabled:
* Phar * Phar
* SPL * SPL
* Date
* fileinfo * fileinfo
* mbstring * mbstring
* Bz2 * Bz2

View File

@@ -1,5 +1,6 @@
### Settings file for magdev/dossier ### Settings file for magdev/dossier
charset: utf-8 charset: utf-8
docname: dossier
# Date formats # Date formats
date: date:

View File

@@ -19,6 +19,10 @@ services:
class: '\Magdev\Dossier\Service\MinifierService' class: '\Magdev\Dossier\Service\MinifierService'
arguments: ['@monolog'] arguments: ['@monolog']
git:
class: '\Magdev\Dossier\Service\GitService'
arguments: ['@config', '@monolog']
translator: translator:
class: '\Magdev\Dossier\Service\TranslatorService' class: '\Magdev\Dossier\Service\TranslatorService'
arguments: ['@config', '@monolog'] arguments: ['@config', '@monolog']

View File

@@ -502,19 +502,6 @@ dl.horizontal {
font-weight: bold; font-weight: bold;
font-size: (@base-font-size + .5pt); font-size: (@base-font-size + .5pt);
} }
dl.horizontal {
display: none;
dt {
text-align: left;
width: 1cm;
}
dd {
padding-right: 1cm;
p {
margin: 0;
}
}
}
p, li { p, li {
line-height: @intro-paragraph-line-height; line-height: @intro-paragraph-line-height;
font-size: @intro-paragraph-size; font-size: @intro-paragraph-size;

View File

@@ -19,6 +19,14 @@
{% endfor %} {% endfor %}
{% endmacro %} {% endmacro %}
{% macro list_projects(projects, tag) %}
{% set tag = tag|default('li') %}
{% for project in projects %}
<{{ tag }}><em>{{ project.name }}:</em>
{{ project.shortDescription }}</{{ tag }}>
{% endfor %}
{% endmacro %}
{% macro list_link_array(entries, tag) %} {% macro list_link_array(entries, tag) %}
{% set tag = tag|default('li') %} {% set tag = tag|default('li') %}

View File

@@ -1,3 +1,5 @@
{% import "macros.html.twig" as macros %}
{% if projects|length > 0 %} {% if projects|length > 0 %}
<section class="projects"> <section class="projects">
<h2>{{ 'projects.header'|trans }}</h2> <h2>{{ 'projects.header'|trans }}</h2>
@@ -6,18 +8,13 @@
{% for project in projects %} {% for project in projects %}
<article class="project"> <article class="project">
<h3>{{ project.name }} {% if project.stack %}<small>({{ project.stack }})</small>{% endif %}</h3> <h3>{{ project.name }} {% if project.stack %}<small>({{ project.stack }})</small>{% endif %}</h3>
<dl class="horizontal">
<dt>{{ 'projects.fields.status'|trans }}</dt>
<dd>
<p class="badge badge-{{ project.status }}">{{ ('projects.status.' ~ project.status)|trans }}</p>
</dd>
{% if project.role %}
<dt>{{ 'projects.fields.role'|trans }}</dt>
<dd>{{ project.role }}</dd>
{% endif %}
</dl>
<p class="short-description">{{ project.shortDescription }}</p> <p class="short-description">{{ project.shortDescription }}</p>
{{ project.content|raw }} {{ project.content|raw }}
{% if project.hasUrls() %}
<ul>
{{ macros.list_link_array(project.urls) }}
</ul>
{% endif %}
</article> </article>
{% endfor %} {% endfor %}
</div> </div>

View File

@@ -115,11 +115,11 @@
{{ macros.list_references(person.references) }} {{ macros.list_references(person.references) }}
</ul> </ul>
{% endif %} {% endif %}
{% if person.projects|length > 0 %} {% if projects|length > 0 %}
<h3>{{ 'resume.headers.current_projects'|trans }}</h3> <h3>{{ 'resume.headers.current_projects'|trans }}</h3>
<ul> <ul>
{{ macros.list_simple_array(person.projects) }} {{ macros.list_projects(projects) }}
</ul> </ul>
{% endif %} {% endif %}

1
bin/.gitignore vendored
View File

@@ -2,3 +2,4 @@
lessc lessc
pscss pscss
.directory .directory
/phpca

View File

@@ -32,12 +32,12 @@
"mnapoli/front-yaml" : "^1.6", "mnapoli/front-yaml" : "^1.6",
"oyejorge/less.php" : "v1.7.0.14", "oyejorge/less.php" : "v1.7.0.14",
"erusev/parsedown-extra" : "^0.7.1", "erusev/parsedown-extra" : "^0.7.1",
"zaininnari/html-minifier" : "*",
"leafo/scssphp" : "^0.7.6", "leafo/scssphp" : "^0.7.6",
"adbario/php-dot-notation" : "^2.0", "adbario/php-dot-notation" : "^2.0",
"magdev/console-form" : "^0.0.7", "magdev/console-form" : "^0.0.7",
"monolog/monolog" : "^1.23", "monolog/monolog" : "^1.23",
"pdfshift/pdfshift-php" : "~1.0.2" "pdfshift/pdfshift-php" : "~1.0.2",
"raivisdejus/html-minifier" : "~0.5"
}, },
"config" : { "config" : {
"bin-dir" : "bin" "bin-dir" : "bin"
@@ -64,5 +64,8 @@
"url" : "git@github.com:magdev/console-form.git", "url" : "git@github.com:magdev/console-form.git",
"name" : "magdev/console-form" "name" : "magdev/console-form"
} }
] ],
"require-dev" : {
"wapmorgan/php-code-analyzer" : "^1.0"
}
} }

726
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -62,7 +62,7 @@ final class DossierBuildCommand extends BaseCommand
->addOption('locale', 'l', InputOption::VALUE_OPTIONAL, 'Set the locale', 'de') ->addOption('locale', 'l', InputOption::VALUE_OPTIONAL, 'Set the locale', 'de')
->addOption('sort', 's', InputOption::VALUE_OPTIONAL, 'Set the sort direction for the CV', CurriculumVitae::SORT_DESC) ->addOption('sort', 's', InputOption::VALUE_OPTIONAL, 'Set the sort direction for the CV', CurriculumVitae::SORT_DESC)
->addOption('theme', 't', InputOption::VALUE_OPTIONAL, 'Select the theme', 'print') ->addOption('theme', 't', InputOption::VALUE_OPTIONAL, 'Select the theme', 'print')
->addOption('docname', 'd', InputOption::VALUE_OPTIONAL, 'Set the name for the output document (w/o extension)', 'dossier') ->addOption('docname', 'd', InputOption::VALUE_OPTIONAL, 'Set the name for the output document (w/o extension)', '')
->addOption('no-cover', null, InputOption::VALUE_NONE, 'Suppress the cover') ->addOption('no-cover', null, InputOption::VALUE_NONE, 'Suppress the cover')
->addOption('no-intro', null, InputOption::VALUE_NONE, 'Suppress the introduction') ->addOption('no-intro', null, InputOption::VALUE_NONE, 'Suppress the introduction')
@@ -97,11 +97,12 @@ final class DossierBuildCommand extends BaseCommand
$cssproc = $this->getService('cssproc'); $cssproc = $this->getService('cssproc');
/* @var $cssroc \Magdev\Dossier\Service\StylesheetProcessorService */ /* @var $cssroc \Magdev\Dossier\Service\StylesheetProcessorService */
$name = $input->getOption('docname') ?: $this->getService('git')->getCurrentBranchName();
try { try {
$data = new DataCollector(array( $data = new DataCollector(array(
'disabled' => $this->getHelper('section_manager')->getDisabledSections($input), 'disabled' => $this->getHelper('section_manager')->getDisabledSections($input),
'theme' => $input->getOption('theme'), 'theme' => $input->getOption('theme'),
'name' => $input->getOption('docname'), 'name' => ($name ?: 'dossier'),
'tags' => $this->config->get('cv.tags'), 'tags' => $this->config->get('cv.tags'),
'locale' => $this->translator->getTranslator()->getLocale(), 'locale' => $this->translator->getTranslator()->getLocale(),
'stylesheet' => $cssproc->parseThemeStyles(), 'stylesheet' => $cssproc->parseThemeStyles(),

View File

@@ -198,7 +198,7 @@ class CurriculumVitae extends BaseCollection
$formatter = $this->formatter; $formatter = $this->formatter;
array_walk($result, function(int &$seconds, string $key) use ($formatter) { array_walk($result, function(int &$seconds, string $key) use ($formatter) {
$seconds = $formatter->formatExperience($seconds); $seconds = $formatter->formatYearMonthDuration($seconds);
}); });
return $result; return $result;
} }

View File

@@ -32,6 +32,7 @@ namespace Magdev\Dossier\Model\CurriculumVitae;
use Magdev\Dossier\Model\AbstractModel; use Magdev\Dossier\Model\AbstractModel;
use Magdev\Dossier\Model\Traits\PhotoTrait; use Magdev\Dossier\Model\Traits\PhotoTrait;
use Magdev\Dossier\Model\Traits\ToggableTrait;
use Mni\FrontYAML\Document; use Mni\FrontYAML\Document;
use Magdev\Dossier\Model\Base\BaseModel; use Magdev\Dossier\Model\Base\BaseModel;
use Magdev\Dossier\Analyzer\Base\AnalyzableInterface; use Magdev\Dossier\Analyzer\Base\AnalyzableInterface;
@@ -46,6 +47,7 @@ use Magdev\Dossier\Model\Base\PhotoInterface;
final class Entry extends BaseModel implements PhotoInterface, AnalyzableInterface final class Entry extends BaseModel implements PhotoInterface, AnalyzableInterface
{ {
use PhotoTrait; use PhotoTrait;
use ToggableTrait;
/** /**
* Start date * Start date

View File

@@ -69,16 +69,6 @@ class Intro extends BaseModel implements PhotoInterface, AnalyzableInterface
protected $showQuotes = self::SHOW_TOP; protected $showQuotes = self::SHOW_TOP;
/**
* Get the headline
*
* @return string
*/
public function getHeadline(): string
{
return $this->headline;
}
/** /**
@@ -93,6 +83,17 @@ class Intro extends BaseModel implements PhotoInterface, AnalyzableInterface
} }
/**
* Get the headline
*
* @return string
*/
public function getHeadline(): string
{
return $this->headline;
}
/** /**
* Get the quotes * Get the quotes
* *

View File

@@ -132,12 +132,6 @@ final class Person extends BaseModel implements PhotoInterface, AnalyzableInterf
*/ */
protected $interests = array(); protected $interests = array();
/**
* Current Projects
* @var array
*/
protected $projects = array();
/** /**
* Constructor * Constructor
@@ -312,17 +306,6 @@ final class Person extends BaseModel implements PhotoInterface, AnalyzableInterf
} }
/**
* Get current projects
*
* @return array
*/
public function getProjects(): array
{
return $this->projects;
}
/** /**
* Get the work license * Get the work license
* *
@@ -388,7 +371,10 @@ final class Person extends BaseModel implements PhotoInterface, AnalyzableInterf
foreach ($value as $type => $address) { foreach ($value as $type => $address) {
if ($type == 'accounts' && is_array($address)) { if ($type == 'accounts' && is_array($address)) {
foreach ($address as $a) { foreach ($address as $a) {
$this->contacts->append(new Contact($a['address'], $a['type'])); $contact = new Contact($a['address'], $a['type'], $a['active']);
if ($contact->isActive()) {
$this->contacts->append($contact);
}
} }
} else { } else {
$this->contacts->append(new Contact($address, $type)); $this->contacts->append(new Contact($address, $type));
@@ -396,7 +382,10 @@ final class Person extends BaseModel implements PhotoInterface, AnalyzableInterf
} }
} else if ($key == 'references') { } else if ($key == 'references') {
foreach ($value as $reference) { foreach ($value as $reference) {
$this->references->append(new Reference($reference)); $ref = new Reference($reference);
if ($ref->isActive()) {
$this->references->append($ref);
}
} }
} else { } else {
$this->setProperty($key, $value); $this->setProperty($key, $value);

View File

@@ -30,6 +30,8 @@
namespace Magdev\Dossier\Model\Person; namespace Magdev\Dossier\Model\Person;
use Magdev\Dossier\Model\Traits\ToggableTrait;
/** /**
* Contact model * Contact model
* *
@@ -37,6 +39,8 @@ namespace Magdev\Dossier\Model\Person;
*/ */
class Contact class Contact
{ {
use ToggableTrait;
/** /**
* Contact address * Contact address
* @var string * @var string
@@ -55,11 +59,13 @@ class Contact
* *
* @param string $address * @param string $address
* @param string $type * @param string $type
* @param bool $active
*/ */
public function __construct(string $address, string $type) public function __construct(string $address, string $type, ?bool $active = true)
{ {
$this->address = $address; $this->address = $address;
$this->type = $type; $this->type = $type;
$this->active = $active;
} }

View File

@@ -31,6 +31,7 @@
namespace Magdev\Dossier\Model\Person; namespace Magdev\Dossier\Model\Person;
use Magdev\Dossier\Model\Base\BaseModel; use Magdev\Dossier\Model\Base\BaseModel;
use Magdev\Dossier\Model\Traits\ToggableTrait;
/** /**
* Model for job references * Model for job references
@@ -39,6 +40,8 @@ use Magdev\Dossier\Model\Base\BaseModel;
*/ */
class Reference extends BaseModel class Reference extends BaseModel
{ {
use ToggableTrait;
/** /**
* Reference description * Reference description
* @var string * @var string

View File

@@ -30,26 +30,43 @@
namespace Magdev\Dossier\Model; namespace Magdev\Dossier\Model;
use Magdev\Dossier\Model\Base\BaseModel; use Magdev\Dossier\Model\Base\BaseModel;
use Magdev\Dossier\Model\Traits\ToggableTrait;
use Mni\FrontYAML\Document;
/**
* Model for projects page
*
* @author magdev
*/
class Project extends BaseModel class Project extends BaseModel
{ {
use ToggableTrait;
/**
* Project name
* @var string
*/
protected $name = ''; protected $name = '';
protected $status = '';
protected $url = ''; /**
* Public URLs
* @var array
*/
protected $urls = array();
/**
* Short Description
* @var string
*/
protected $shortDescription = ''; protected $shortDescription = '';
/**
* Project stack
* @var string
*/
protected $stack = ''; protected $stack = '';
protected $role = '';
public function getRole(): string
{
return $this->role;
}
public function getStack(): string public function getStack(): string
{ {
@@ -57,35 +74,26 @@ class Project extends BaseModel
} }
public function getName(): string public function getName(): string
{ {
return $this->name; return $this->name;
} }
public function hasUrls(): bool
public function getStatus(): string
{ {
return $this->status; return sizeof($this->urls) > 0;
} }
public function getUrls(): array
public function getUrl(): string
{ {
return $this->url; return $this->urls;
} }
public function getShortDescription(): string public function getShortDescription(): string
{ {
return $this->shortDescription; return $this->shortDescription;
} }
} }

View File

@@ -0,0 +1,91 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2019 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2019 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Magdev\Dossier\Model\Traits;
/**
* Trait for objects which can be de-/activated
*
* @author magdev
*/
trait ToggableTrait
{
/**
* @var bool
*/
protected $active = true;
/**
* Activate object
*
* @return self
*/
public function activate(): self
{
$this->active = true;
return self;
}
/**
* Deactivate object
*
* @return self
*/
public function deactivate(): self
{
$this->active = false;
return $this;
}
/**
* Toggle current activation status
*
* @return self
*/
public function toggle(): self
{
$this->active = !$this->active;
return $this;
}
/**
* Check if object is activated
*
* @return bool
*/
public function isActive(): bool
{
return $this->active;
}
}

115
src/Service/GitService.php Normal file
View File

@@ -0,0 +1,115 @@
<?php
/**
* The MIT License (MIT)
*
* Copyright (c) 2019 magdev
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author magdev
* @copyright 2019 Marco Grätsch
* @package magdev/dossier
* @license http://opensource.org/licenses/MIT MIT License
*/
namespace Magdev\Dossier\Service;
// git branch | grep \* | cut -d ' ' -f2
class GitService
{
/**
* Configuration service
* @var \Magdev\Dossier\Service\ConfigService
*/
protected $config = null;
/**
* Monolog service
* @var \Magdev\Dossier\Service\MonologService
*/
protected $logger = null;
/**
* Constructor
*
* @param \Magdev\Dossier\Service\ConfigService $config
* @param \Magdev\Dossier\Service\MonologService $logger
*/
public function __construct(ConfigService $config, MonologService $logger)
{
$this->config = $config;
$this->logger = $logger;
}
/**
* Initialize a new repository
*
* @return bool
*/
public function init(): bool
{
if (!$this->isGitRepository()) {
$this->exec('git init');
}
return $this->isGitRepository();
}
/**
* Get the current branch name
*
* @return string
*/
public function getCurrentBranchName(): string
{
if (!$this->isGitRepository()) {
return $this->config->get('docname');
}
$output = $this->exec('git branch | grep \\\* | cut -d \' \' -f2');
return $output[0];
}
/**
* Check if repository is initialized
*
* @return bool
*/
public function isGitRepository(): bool
{
return is_dir(PROJECT_ROOT.'/.git') && file_exists(PROJECT_ROOT.'/.git/config');
}
/**
* Execute a system command
*
* @param string $cmd
* @return array
*/
protected function exec(string $cmd): array
{
$output = array();
exec($cmd, $output);
return $output;
}
}

View File

@@ -108,7 +108,10 @@ class MarkdownService
foreach ($files as $file) { foreach ($files as $file) {
/* @var $file \SplFileInfo */ /* @var $file \SplFileInfo */
$document = $this->getDocument($file->getPathname()); $document = $this->getDocument($file->getPathname());
$cv->append(new CurriculumVitae\Entry($document)); $entry = new CurriculumVitae\Entry($document);
if ($entry->isActive()) {
$cv->append($entry);
}
} }
$cv->setSortDirection($sort)->sort(); $cv->setSortDirection($sort)->sort();
@@ -117,7 +120,10 @@ class MarkdownService
foreach ($files as $file) { foreach ($files as $file) {
/* @var $file \SplFileInfo */ /* @var $file \SplFileInfo */
$document = $this->getDocument($file->getPathname()); $document = $this->getDocument($file->getPathname());
$projects->append(new Project($document)); $project = new Project($document);
if ($project->isActive()) {
$projects->append($project);
}
} }

View File

@@ -120,13 +120,15 @@ class TemplateService
{ {
$theme = !$theme ? $this->theme : $theme; $theme = !$theme ? $this->theme : $theme;
if (getenv('DOSSIER_THEME_DIR')) { if (getenv('APP_ENV') == 'prod') {
if (is_dir(getenv('DOSSIER_THEME_DIR').'/'.$theme) && file_exists(getenv('DOSSIER_THEME_DIR').'/'.$theme.'/'.$file)) { if (getenv('DOSSIER_THEME_DIR')) {
return getenv('DOSSIER_THEME_DIR').'/'.$theme.'/'.$file; if (is_dir(getenv('DOSSIER_THEME_DIR').'/'.$theme) && file_exists(getenv('DOSSIER_THEME_DIR').'/'.$theme.'/'.$file)) {
return getenv('DOSSIER_THEME_DIR').'/'.$theme.'/'.$file;
}
}
if (is_dir(getenv('HOME').'/.dossier/tpl/'.$theme) && file_exists(getenv('HOME').'/.dossier/tpl/'.$theme.'/'.$file)) {
return getenv('HOME').'/.dossier/tpl/'.$theme.'/'.$file;
} }
}
if (is_dir(getenv('HOME').'/.dossier/tpl/'.$theme) && file_exists(getenv('HOME').'/.dossier/tpl/'.$theme.'/'.$file)) {
return getenv('HOME').'/.dossier/tpl/'.$theme.'/'.$file;
} }
return DOSSIER_ROOT.'/app/tpl/'.$theme.'/'.$file; return DOSSIER_ROOT.'/app/tpl/'.$theme.'/'.$file;
} }
@@ -143,16 +145,23 @@ class TemplateService
$this->theme = $theme; $this->theme = $theme;
$loaders = array(); $loaders = array();
if (getenv('DOSSIER_THEME_DIR') && is_dir(getenv('DOSSIER_THEME_DIR').'/'.$theme)) { if (getenv('APP_ENV') == 'prod') {
$loaders[] = new \Twig_Loader_Filesystem(getenv('DOSSIER_THEME_DIR').'/'.$theme); if (getenv('DOSSIER_THEME_DIR') && is_dir(getenv('DOSSIER_THEME_DIR').'/'.$theme)) {
} $loaders[] = new \Twig_Loader_Filesystem(getenv('DOSSIER_THEME_DIR').'/'.$theme);
if (is_dir(getenv('HOME').'/.dossier/tpl/'.$theme)) { }
$loaders[] = new \Twig_Loader_Filesystem(getenv('HOME').'/.dossier/tpl/'.$theme); if (is_dir(getenv('HOME').'/.dossier/tpl/'.$theme)) {
$loaders[] = new \Twig_Loader_Filesystem(getenv('HOME').'/.dossier/tpl/'.$theme);
}
} }
$loaders[] = new \Twig_Loader_Filesystem(DOSSIER_ROOT.'/app/tpl/'.$theme); $loaders[] = new \Twig_Loader_Filesystem(DOSSIER_ROOT.'/app/tpl/'.$theme);
$cache = false;
if (getenv('APP_ENV') == 'prod') {
$cache = new \Twig_Cache_Filesystem(DOSSIER_CACHE, \Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION);
}
$this->twig = new \Twig_Environment(new \Twig_Loader_Chain($loaders), array( $this->twig = new \Twig_Environment(new \Twig_Loader_Chain($loaders), array(
'cache' => new \Twig_Cache_Filesystem(DOSSIER_CACHE, \Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION), 'cache' => $cache,
'debug' => getenv('APP_DEBUG'), 'debug' => getenv('APP_DEBUG'),
)); ));
$this->addTwigExtensions($this->translator->getTranslator(), $this->config); $this->addTwigExtensions($this->translator->getTranslator(), $this->config);
@@ -205,9 +214,6 @@ class TemplateService
*/ */
public function render(string $template, DataCollectorInterface $data, string $destDir): string public function render(string $template, DataCollectorInterface $data, string $destDir): string
{ {
if (!is_dir($destDir)) {
mkdir($destDir, 0755, true);
}
$vars = $data->getData(); $vars = $data->getData();
$name = isset($vars['name']) ? $vars['name'] : $this->docname; $name = isset($vars['name']) ? $vars['name'] : $this->docname;
$name .= isset($vars['theme']) ? '.'.$vars['theme'] : ''; $name .= isset($vars['theme']) ? '.'.$vars['theme'] : '';
@@ -215,6 +221,10 @@ class TemplateService
$html = $this->twig->render($template, $vars); $html = $this->twig->render($template, $vars);
$html = $this->minifier->minify($html); $html = $this->minifier->minify($html);
if (!is_dir(dirname($path))) {
mkdir(dirname($path), 0755, true);
}
if (!file_put_contents($path, $html)) { if (!file_put_contents($path, $html)) {
throw new \RuntimeException('Error writing output file: '.$path); throw new \RuntimeException('Error writing output file: '.$path);
} }
@@ -290,7 +300,7 @@ class TemplateService
}, array('is_safe' => array('html')))); }, array('is_safe' => array('html'))));
$this->twig->addFilter(new \Twig_Filter('debug', function ($var) { $this->twig->addFilter(new \Twig_Filter('debug', function ($var) {
return getenv('APP_DEBUG') == true ? '<code>'.print_r($var, true).'</code>' : ''; return getenv('APP_DEBUG') == true || getenv('APP_ENV') == 'dev' ? '<code>'.print_r($var, true).'</code>' : '';
}, array('is_safe' => array('html')))); }, array('is_safe' => array('html'))));
$this->twig->addFunction(new \Twig_Function('is_today', function (\DateTime $checkDate) { $this->twig->addFunction(new \Twig_Function('is_today', function (\DateTime $checkDate) {