Repository navigation
Expand file tree
/
Copy pathPvcRendererNative.module
More file actions
83 lines (70 loc) · 1.86 KB
/
Copy pathPvcRendererNative.module
File metadata and controls
83 lines (70 loc) · 1.86 KB
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
<?php
/**
* Pvc Native Renderer Class V. 0.5.0
* Part of Pvc, a module for ProcessWire 2.3+
*
* by Oliver Wehn
* https://github.com/oliverwehn
*
* Renderer that processes templated with good ol’ fashioned
* PHP and PW API calls.
*
*/
require_once('PvcRenderer.php');
class PvcRendererNative extends PvcRenderer {
const RENDERER_NAME = 'Native';
public static function getModuleInfo(){
return array(
'title' => 'Pvc Native Renderer',
'summary' => __('PVC Renderer using PHP based templates like you are used to with ProcessWire.'),
'autoload' => true,
'version' => 100,
'author' => 'Oliver Wehn',
'href' => 'https://github.com/oliverwehn/Pvc',
'singular' => true,
'requires' => ['PvcCore']
);
}
public function init() {
}
public function ___render(PvcView $view, Array $scope, $filename=NULL) {
if($filename !== NULL) {
if(!file_exists($filename)) throw new WireException(sprintf($this->_('"%s" is not a valid view file.'), $filename));
}
else {
$filename = $view->filename;
}
foreach($scope as $k=>&$v) {
if($v instanceof \Closure) {
$$k = $v();
}
else {
$$k = $v;
}
unset($v);
}
// declare view helpers as global functions
$viewHelpers = $view->getViewHelpers($scope);
$this->set('helpers', $viewHelpers);
foreach($viewHelpers as $name => $method) {
if(!function_exists($name)) {
$this->_declareHelper($name);
}
}
ob_start();
require($filename);
$out = ob_get_contents();
ob_end_clean();
return trim($out);
}
protected function _process_snippet($snippet_path) {
$globals = $this->current['scope'];
$renderer =& $this;
extract($globals);
ob_start();
include($snippet_path);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
}