-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplateEnginePug.module.php
executable file
·128 lines (111 loc) · 4.32 KB
/
TemplateEnginePug.module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
namespace ProcessWire;
use TemplateEnginePug\TemplateEnginePug as PugEngine;
/**
* Adds Pug templates to the TemplateEngineFactory module.
*/
class TemplateEnginePug extends WireData implements Module, ConfigurableModule
{
/**
* @var array
*/
private static $defaultConfig = [
'template_files_suffix' => 'pug',
'api_vars_available' => 1,
'pretty' => 0,
'debug' => 1,
'profiler' => 0,
'optimizer' => 0,
];
public function __construct()
{
parent::__construct();
$this->wire('classLoader')->addNamespace('TemplateEnginePug', __DIR__ . '/src');
$this->setDefaultConfig();
}
/**
* @return array
*/
public static function getModuleInfo()
{
return [
'title' => 'Template Engine Pug',
'summary' => 'Pug templates for the TemplateEngineFactory',
'version' => 203,
'author' => 'Diktus Dreibholz',
'href' => 'https://github.com/dreerr/TemplateEnginePug/',
'singular' => true,
'autoload' => true,
'requires' => [
'TemplateEngineFactory>=2.0.0',
'PHP>=7.0',
'ProcessWire>=3.0',
],
];
}
public function init()
{
/** @var \ProcessWire\TemplateEngineFactory $factory */
$factory = $this->wire('modules')->get('TemplateEngineFactory');
$factory->registerEngine('Pug', new PugEngine($factory->getArray(), $this->getArray()));
}
private function setDefaultConfig()
{
foreach (self::$defaultConfig as $key => $value) {
$this->set($key, $value);
}
}
/**
* @param array $data
*
* @throws \ProcessWire\WireException
* @throws \ProcessWire\WirePermissionException
*
* @return \ProcessWire\InputfieldWrapper
*/
public static function getModuleConfigInputfields(array $data)
{
/** @var Modules $modules */
$data = array_merge(self::$defaultConfig, $data);
$wrapper = new InputfieldWrapper();
$modules = wire('modules');
/** @var \ProcessWire\InputfieldText $field */
$field = $modules->get('InputfieldText');
$field->label = __('Template files suffix');
$field->name = 'template_files_suffix';
$field->value = $data['template_files_suffix'];
$field->required = 1;
$wrapper->append($field);
$field = $modules->get('InputfieldCheckbox');
$field->label = __('Provide ProcessWire API variables in Pug templates');
$field->description = __('API variables (`$pages`, `$input`, `$config`...) are accessible in Pug, e.g. `{{ config }}` for the config API variable.');
$field->name = 'api_vars_available';
$field->checked = (bool) $data['api_vars_available'];
$wrapper->append($field);
$field = $modules->get('InputfieldCheckbox');
$field->label = __('Output indented HTML');
$field->description = __('Output rendered templates as indented HTML');
$field->name = 'pretty';
$field->checked = (bool) $data['pretty'];
$wrapper->append($field);
$field = $modules->get('InputfieldCheckbox');
$field->label = __('Debug Output');
$field->description = __('When an error occurs at render time, you will get a complete stack trace including line and offset in the original pug source file.');
$field->name = 'debug';
$field->checked = (bool) $data['debug'];
$wrapper->append($field);
$field = $modules->get('InputfieldCheckbox');
$field->label = __('Enable Profiler');
$field->description = __('When set to true, it will output on render a timeline you can inspect in your browser to see wich token/node take longer to lex/parse/compile/render.');
$field->name = 'profiler';
$field->checked = (bool) $data['profiler'];
$wrapper->append($field);
$field = $modules->get('InputfieldCheckbox');
$field->label = __('Use Optimizer');
$field->description = __('The Optimizer is a tool that avoid to load the Phug engine if a file is available in the cache.');
$field->name = 'optimizer';
$field->checked = (bool) $data['optimizer'];
$wrapper->append($field);
return $wrapper;
}
}