initial commmit
This commit is contained in:
commit
88fc338b55
3 changed files with 57 additions and 0 deletions
27
klein.php
Normal file
27
klein.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
class Klein {
|
||||
static function render($html, $vars) {
|
||||
$data = file_get_contents($html);
|
||||
$pattern = array(
|
||||
"/{%\s*for\s+(\w+)\s+in\s+(\w+)\s*%}/" => "<?php foreach(\$$2 as \$$1): ?>",
|
||||
"/{%\s*if\s+(\w+)\s*%}/" => "<?php if(isset(\$$1)): ?>",
|
||||
"/{%\s*block\s+(\w+)\s*%}/" => "<?php function $1() { ?>",
|
||||
"/{%\s*endblock\s*%}/" => "<?php } ?>",
|
||||
"/{%\s*endfor\s*%}/" => "<?php endforeach; ?>",
|
||||
"/{%\s*endif\s*%}/" => "<?php endif; ?>",
|
||||
"/{{\s*(\w+)\s*}}/" => "<?php echo \$$1; ?>",
|
||||
);
|
||||
|
||||
$result = $data;
|
||||
foreach($pattern as $key => $value) {
|
||||
$result = preg_replace($key, $value, $result);
|
||||
}
|
||||
|
||||
extract($vars);
|
||||
|
||||
ob_start();
|
||||
eval(" ?>".$result."<?php ");
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue