PluginProbe
Packeta / 1.5.4
Packeta v1.5.4
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / LatteEngineFactory.php

LatteEngineFactory.php in Packeta 1.5.4, at src/Packetery/Module/LatteEngineFactory.php

57 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class PacketeryLatte_Engine_Factory
4 *
5 * @package Packetery
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module;
11
12 use PacketeryLatte\Engine;
13 use PacketeryLatte\MacroNode;
14 use PacketeryLatte\Macros\MacroSet;
15 use PacketeryLatte\PhpWriter;
16 use PacketeryNette\Bridges\FormsPacketeryLatte\FormMacros;
17
18 /**
19 * Class PacketeryLatte_Engine_Factory
20 *
21 * @package Packetery
22 */
23 class LatteEngineFactory {
24
25 /**
26 * Creates latte engine factory
27 *
28 * @param string $temp_dir Temporary folder.
29 *
30 * @return Engine
31 */
32 public function create( string $temp_dir ): Engine {
33 $engine = new Engine();
34 $engine->setTempDirectory( $temp_dir );
35 FormMacros::install( $engine->getCompiler() );
36 $engine->addFilter(
37 'wpDateTime',
38 function ( \DateTimeInterface $value ) {
39 return $value->format( wc_date_format() . ' ' . wc_time_format() );
40 }
41 );
42
43 $macroSet = new MacroSet( $engine->getCompiler() );
44 $macroSet->addMacro(
45 'phpComment',
46 function ( MacroNode $node, PhpWriter $writer ) {
47 $output = trim( $node->args, "'" );
48 $output = preg_replace( '~/~', '|', $output );
49 return $writer->write( '/* ' . $output . ' */' );
50 }
51 );
52
53 $engine->addMacro( 'packetery-macro-set', $macroSet );
54 return $engine;
55 }
56 }
57