Browse Source

add formatType filter

master
ghost 9 months ago
parent
commit
335f4e8fcd
  1. 74
      src/Twig/AppExtension.php
  2. 4
      templates/default/main/index.html.twig
  3. 2
      templates/default/main/index.rss.twig
  4. 4
      templates/default/main/namespace.html.twig
  5. 2
      templates/default/main/namespace.rss.twig
  6. 4
      templates/default/main/transaction.html.twig

74
src/Twig/AppExtension.php

@ -17,6 +17,13 @@ class AppExtension extends AbstractExtension
$this, $this,
'jIdenticon' 'jIdenticon'
] ]
),
new TwigFilter(
'format_type',
[
$this,
'formatType'
]
) )
]; ];
} }
@ -50,4 +57,71 @@ class AppExtension extends AbstractExtension
$format $format
); );
} }
public function formatType(
mixed $value,
int $code
): string
{
switch ($code)
{
case \Kvazar\Index\Manticore::TYPE_NULL:
return '[null]';
case \Kvazar\Index\Manticore::TYPE_BOOL:
return sprintf(
'[bool:%s]',
$value ? 'true' : 'false'
);
case \Kvazar\Index\Manticore::TYPE_INT:
return sprintf(
'[int:%d]',
$value
);
case \Kvazar\Index\Manticore::TYPE_FLOAT:
return sprintf(
'[float:%s]',
$value
);
case \Kvazar\Index\Manticore::TYPE_STRING:
return (string) nl2br(
$value
);
case \Kvazar\Index\Manticore::TYPE_BIN:
return '[binary]';
case \Kvazar\Index\Manticore::TYPE_JSON:
return '[json]';
case \Kvazar\Index\Manticore::TYPE_XML:
return '[xml]';
case \Kvazar\Index\Manticore::TYPE_BASE_64:
return '[base64]';
case \Kvazar\Index\Manticore::TYPE_ARRAY:
return '[array]';
case \Kvazar\Index\Manticore::TYPE_OBJECT:
return '[array]';
default:
return '[undefined]';
}
}
} }

4
templates/default/main/index.html.twig

@ -24,10 +24,10 @@
</div> </div>
<a class="d-block" href="{{ path('main_transaction',{'transaction':record.transaction}) }}"> <a class="d-block" href="{{ path('main_transaction',{'transaction':record.transaction}) }}">
<div class="f-s-16 mb-16 of-a"> <div class="f-s-16 mb-16 of-a">
{{ record.key }} {{ record.key | format_type(record.type.key) }}
</div> </div>
<div class="mb-20 of-a"> <div class="mb-20 of-a">
{{ record.value | nl2br }} {{ record.value | format_type(record.type.value) }}
</div> </div>
<div class="f-s-12"> <div class="f-s-12">
{{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }} {{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }}

2
templates/default/main/index.rss.twig

@ -6,7 +6,7 @@
<link>{{ url('main_index') }}</link> <link>{{ url('main_index') }}</link>
{% for record in records %} {% for record in records %}
<item> <item>
<title>{{ record.key }}</title> <title>{{ record.key | format_type(record.type.key) }}</title>
<author>{{ record.namespace }}</author> <author>{{ record.namespace }}</author>
<pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate> <pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid> <guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid>

4
templates/default/main/namespace.html.twig

@ -25,10 +25,10 @@
<div class="mx-a mw-560 px-16"> <div class="mx-a mw-560 px-16">
<a class="d-block" href="{{ path('main_transaction',{'transaction':record.transaction}) }}"> <a class="d-block" href="{{ path('main_transaction',{'transaction':record.transaction}) }}">
<div class="f-s-16 mb-16 of-a"> <div class="f-s-16 mb-16 of-a">
{{ record.key }} {{ record.key | format_type(record.type.key) }}
</div> </div>
<div class="mb-20 of-a"> <div class="mb-20 of-a">
{{ record.value | nl2br }} {{ record.value | format_type(record.type.value) }}
</div> </div>
<div class="f-s-12"> <div class="f-s-12">
{{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }} {{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }}

2
templates/default/main/namespace.rss.twig

@ -6,7 +6,7 @@
<link>{{ url('main_namespace',{'namespace':request.get('namespace')}) }}</link> <link>{{ url('main_namespace',{'namespace':request.get('namespace')}) }}</link>
{% for record in records %} {% for record in records %}
<item> <item>
<title>{{ record.key }}</title> <title>{{ record.key | format_type(record.type.key) }}</title>
<author>{{ record.namespace }}</author> <author>{{ record.namespace }}</author>
<pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate> <pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate>
<guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid> <guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid>

4
templates/default/main/transaction.html.twig

@ -25,10 +25,10 @@
<div class="t-center px-16"> <div class="t-center px-16">
<div class="mx-a mw-560 px-16"> <div class="mx-a mw-560 px-16">
<div class="f-s-16 mb-16 of-a"> <div class="f-s-16 mb-16 of-a">
{{ record.key }} {{ record.key | format_type(record.type.key) }}
</div> </div>
<div class="mb-20 of-a"> <div class="mb-20 of-a">
{{ record.value | nl2br }} {{ record.value | format_type(record.type.value) }}
</div> </div>
<div class="f-s-12"> <div class="f-s-12">
{{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }} {{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }}

Loading…
Cancel
Save