From 665e9eedc354d27ac344346449e01f3773434c56 Mon Sep 17 00:00:00 2001 From: magdev Date: Sun, 16 Dec 2018 13:38:46 +0100 Subject: [PATCH] template caching disabled in debug mode, cleanup projects page --- app/tpl/print/less/global.less | 13 ------ app/tpl/print/parts/projects.html.twig | 20 +++------ src/Model/Intro.php | 21 ++++----- src/Model/Project.php | 59 ++++++++++++++------------ src/Service/TemplateService.php | 35 +++++++++------ 5 files changed, 72 insertions(+), 76 deletions(-) diff --git a/app/tpl/print/less/global.less b/app/tpl/print/less/global.less index 6fe3eda..09a9dbc 100644 --- a/app/tpl/print/less/global.less +++ b/app/tpl/print/less/global.less @@ -502,19 +502,6 @@ dl.horizontal { font-weight: bold; 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 { line-height: @intro-paragraph-line-height; font-size: @intro-paragraph-size; diff --git a/app/tpl/print/parts/projects.html.twig b/app/tpl/print/parts/projects.html.twig index b059960..137a1e8 100644 --- a/app/tpl/print/parts/projects.html.twig +++ b/app/tpl/print/parts/projects.html.twig @@ -1,3 +1,5 @@ +{% import "macros.html.twig" as macros %} + {% if projects|length > 0 %}

{{ 'projects.header'|trans }}

@@ -6,21 +8,13 @@ {% for project in projects %}

{{ project.name }} {% if project.stack %}({{ project.stack }}){% endif %}

-
-
{{ 'projects.fields.status'|trans }}
-
-

{{ ('projects.status.' ~ project.status)|trans }}

-
- {% if project.role %} -
{{ 'projects.fields.role'|trans }}
-
{{ project.role }}
- {% endif %} -

{{ project.shortDescription }}

- {% if project.repository %} -

{{ project.repository }}

- {% endif %} {{ project.content|raw }} + {% if project.hasUrls() %} +
    + {{ macros.list_link_array(project.urls) }} +
+ {% endif %}
{% endfor %} diff --git a/src/Model/Intro.php b/src/Model/Intro.php index b935f70..089cc2d 100644 --- a/src/Model/Intro.php +++ b/src/Model/Intro.php @@ -69,16 +69,6 @@ class Intro extends BaseModel implements PhotoInterface, AnalyzableInterface 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 * diff --git a/src/Model/Project.php b/src/Model/Project.php index 485a0ce..ea922f2 100644 --- a/src/Model/Project.php +++ b/src/Model/Project.php @@ -30,26 +30,40 @@ namespace Magdev\Dossier\Model; - use Magdev\Dossier\Model\Base\BaseModel; +use Mni\FrontYAML\Document; +/** + * Model for projects page + * + * @author magdev + */ class Project extends BaseModel { + /** + * Project name + * @var string + */ protected $name = ''; - protected $status = ''; - protected $url = ''; + + /** + * Public URLs + * @var array + */ + protected $urls = array(); + + /** + * Short Description + * @var string + */ protected $shortDescription = ''; + + /** + * Project stack + * @var string + */ protected $stack = ''; - protected $role = ''; - - - - public function getRole(): string - { - return $this->role; - } - - + public function getStack(): string { @@ -57,35 +71,26 @@ class Project extends BaseModel } - public function getName(): string { return $this->name; } - - - public function getStatus(): string + + public function hasUrls(): bool { - return $this->status; + return sizeof($this->urls) > 0; } - - public function getUrl(): string + public function getUrls(): array { - return $this->url; + return $this->urls; } - public function getShortDescription(): string { return $this->shortDescription; } - - - - } - diff --git a/src/Service/TemplateService.php b/src/Service/TemplateService.php index ec2be45..282569b 100644 --- a/src/Service/TemplateService.php +++ b/src/Service/TemplateService.php @@ -120,13 +120,15 @@ class TemplateService { $theme = !$theme ? $this->theme : $theme; - if (getenv('DOSSIER_THEME_DIR')) { - if (is_dir(getenv('DOSSIER_THEME_DIR').'/'.$theme) && file_exists(getenv('DOSSIER_THEME_DIR').'/'.$theme.'/'.$file)) { - return getenv('DOSSIER_THEME_DIR').'/'.$theme.'/'.$file; + if (getenv('APP_ENV') == 'prod') { + if (getenv('DOSSIER_THEME_DIR')) { + 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; } @@ -143,16 +145,23 @@ class TemplateService $this->theme = $theme; $loaders = array(); - 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 (getenv('APP_ENV') == 'prod') { + 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); + } } $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( - 'cache' => new \Twig_Cache_Filesystem(DOSSIER_CACHE, \Twig_Cache_Filesystem::FORCE_BYTECODE_INVALIDATION), + 'cache' => $cache, 'debug' => getenv('APP_DEBUG'), )); $this->addTwigExtensions($this->translator->getTranslator(), $this->config); @@ -290,7 +299,7 @@ class TemplateService }, array('is_safe' => array('html')))); $this->twig->addFilter(new \Twig_Filter('debug', function ($var) { - return getenv('APP_DEBUG') == true ? ''.print_r($var, true).'' : ''; + return getenv('APP_DEBUG') == true || getenv('APP_ENV') == 'dev' ? ''.print_r($var, true).'' : ''; }, array('is_safe' => array('html')))); $this->twig->addFunction(new \Twig_Function('is_today', function (\DateTime $checkDate) {