Skip to content

Commit

Permalink
Move templates from Utils lib to make them overridable.
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Nikolaev committed Jul 28, 2021
1 parent 91a164e commit ccba9dc
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ $ /usr/bin/env php bin/console darvin:utils:translations:title-case <pathname>
7.3.10: Add Varnish cache clear command.

7.4.0: Add data view services.

7.5.0: Move templates from Utils lib to make them overridable.
23 changes: 6 additions & 17 deletions DependencyInjection/DarvinUtilsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,14 @@ public function prepend(ContainerBuilder $container): void
'twig',
]);

if ($container->hasExtension('framework') || $container->hasExtension('twig')) {
$dir = sprintf('%s/../Resources', dirname((new \ReflectionClass(ExtensionConfigurator::class))->getFileName()));

if ($container->hasExtension('framework')) {
$container->prependExtensionConfig('framework', [
'translator' => [
'paths' => [
sprintf('%s/translations', $dir),
],
],
]);
}
if ($container->hasExtension('twig')) {
$container->prependExtensionConfig('twig', [
if ($container->hasExtension('framework')) {
$container->prependExtensionConfig('framework', [
'translator' => [
'paths' => [
sprintf('%s/views', $dir) => 'DarvinUtils',
sprintf('%s/translations', sprintf('%s/../Resources', dirname((new \ReflectionClass(ExtensionConfigurator::class))->getFileName()))),
],
]);
}
],
]);
}
}

Expand Down
63 changes: 63 additions & 0 deletions Resources/views/data/view/block.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% macro block(view, show_title = true) %}
<div class="details-list__property">

{% if show_title and view.hasTitle %}
<span class="details-list__property-name"
style="font-family: Arial, sans-serif; font-size: 15px; line-height: 23px; color: #7e7e7e;">
{{ view.title }}
</span>
{% endif %}

<span class="details-list__property-value"
style="font-family: Arial, sans-serif; font-size: 15px; line-height: 23px; color: #333333;">

{% if view.empty %}
&mdash;
{% else %}

{% if view.hasChildren %}

{% if view.associative %}
<ul>

{% for child in view.children %}
<li>{{ _self.block(child) }}</li>
{% endfor %}

</ul>
{% else %}
<ol>

{% for child in view.children %}
<li>{{ _self.block(child) }}</li>
{% endfor %}

</ol>
{% endif %}

{% endif %}

{% if view.hasValue %}

{% if view.hasUrl %}
<a href="{{ view.url }}"
style="font-family: Arial, sans-serif; font-size: 15px; line-height: 23px; color: #333333;">
{{ view.value }}
</a>
{% else %}
{{ view.value|raw }}
{% endif %}

{% endif %}

{% endif %}

</span>
</div>
{% endmacro %}

{% if view %}

{{ _self.block(view, false) }}

{% endif %}
63 changes: 63 additions & 0 deletions Resources/views/data/view/table.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% macro row(view, show_title = true) %}
<tr>

{% if show_title and view.hasTitle %}
<th>{{ view.title }}</th>
{% endif %}

<td>

{% if view.empty %}
&mdash;
{% else %}

{% if view.hasChildren %}
<table>

{% for child in view.children %}

{{ _self.row(child) }}

{% endfor %}

</table>
{% endif %}

{% if view.hasValue %}

{% if view.hasUrl %}
<a href="{{ view.url }}"
style="font-family: Arial, sans-serif; font-size: 15px; line-height: 23px; color: #333333;">
{{ view.value }}
</a>
{% else %}
{{ view.value|raw }}
{% endif %}

{% endif %}

{% endif %}

</td>
<tr>
{% endmacro %}

{% if view %}
<table>

{% if view.hasChildren %}

{% for child in view.children %}

{{ _self.row(child) }}

{% endfor %}

{% else %}

{{ _self.row(view, false) }}

{% endif %}

</table>
{% endif %}
33 changes: 33 additions & 0 deletions Resources/views/data/view/text.txt.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{%- macro text(view, level = 0) -%}

{%- if level > 0 and view.hasTitle -%}
{{- view.title ~ ': ' -}}
{%- endif -%}

{%- if view.empty -%}
-
{%- else -%}

{%- if view.hasChildren -%}

{%- for child in view.children %}

{% if level > 0 %}{% for i in 1..level %}{{ ' ' }}{% endfor %}{% endif %}{{ _self.text(child, level + 1) -}}

{%- endfor -%}

{%- endif -%}

{%- if view.hasValue -%}
{{- view.value|striptags -}}
{%- endif -%}

{%- endif -%}

{%- endmacro -%}

{%- if view -%}

{{- _self.text(view) -}}

{%- endif -%}
3 changes: 3 additions & 0 deletions Resources/views/fields.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{%- block darvin_utils_anti_spam_row -%}
{{- form_widget(form) -}}
{%- endblock darvin_utils_anti_spam_row -%}
5 changes: 5 additions & 0 deletions Resources/views/macros.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro div_data(data, name, trans_domain = 'messages') %}{{ utils_data_render('block', data, name, trans_domain) }}{% endmacro %}

{% macro plain_data(data, name, trans_domain = 'messages') %}{{ utils_data_render('text', data, name, trans_domain) }}{% endmacro %}

{% macro table_data(data, name, trans_domain = 'messages') %}{{ utils_data_render('table', data, name, trans_domain) }}{% endmacro %}
41 changes: 41 additions & 0 deletions Resources/views/override/entity.php.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types=1);
/**
* @copyright Copyright (c) {{ 'now'|date('Y') }}, Darvin Studio
* @link https://www.darvin-studio.ru
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Entity\{{ package_namespace }}{% if entity_namespace %}\{{ entity_namespace }}{% endif %};
use {{ fqcn }};
use Doctrine\ORM\Mapping as ORM;
/**
* {{ class|humanize }}
*
* @ORM\Entity{% if has_repository %}(repositoryClass="App\Repository\{{ package_namespace }}{% if entity_namespace %}\{{ entity_namespace }}{% endif %}\{{ class }}Repository"){% endif %}
*/
class App{{ class }} extends {{ class }}
{
{% if translatable %}
/**
* {@inheritDoc}
*/
public static function getTranslatableEntityClass(): string
{
return App{{ translatable }}::class;
}
{% endif %}
{% if translation %}
/**
* {@inheritDoc}
*/
public static function getTranslationEntityClass(): string
{
return App{{ translation }}::class;
}
{% endif %}
}
19 changes: 19 additions & 0 deletions Resources/views/override/repository.php.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);
/**
* @copyright Copyright (c) {{ 'now'|date('Y') }}, Darvin Studio
* @link https://www.darvin-studio.ru
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Repository\{{ package_namespace }}{% if entity_namespace %}\{{ entity_namespace }}{% endif %};
use {{ repository }} as Base{{ class }}Repository;
/**
* {{ class|humanize }} entity repository
*/
class {{ class }}Repository extends Base{{ class }}Repository
{
}
5 changes: 5 additions & 0 deletions Resources/views/price.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if price > 0 or options.allow_empty %}
{{ ('price.value.' ~ options.format)|trans({'%price%': price|number_format(0, null, options.thousands_separator), '%count%': price|number_format(0, '', '')})|raw }}
{% else %}
{{ ('price.empty.' ~ options.empty_format)|trans|raw }}
{% endif %}

0 comments on commit ccba9dc

Please sign in to comment.