обновление которое может сломать часть примеров

This commit is contained in:
andrey 2017-03-29 10:34:59 +03:00
parent 3b7e186fda
commit f11b9b3e56
7 changed files with 22 additions and 30 deletions

View file

@ -3,13 +3,7 @@
class Klein { class Klein {
public $code; public $code;
function __construct($html = null) { function _construct($html) {
if ($html) {
$this->compile($html);
}
}
function compile($html) {
$pattern = array_map(function ($grammar) { $pattern = array_map(function ($grammar) {
list(, $result) = $grammar; list(, $result) = $grammar;
$body = strtr($grammar[0], [' ' => "\s*", '+' => "\s+", ':var' => "(\w+(\s*\.\s*\w+)*)", ':id' => "(\w+)", '{{' => "{{\!?"]); $body = strtr($grammar[0], [' ' => "\s*", '+' => "\s+", ':var' => "(\w+(\s*\.\s*\w+)*)", ':id' => "(\w+)", '{{' => "{{\!?"]);

View file

@ -1,6 +1,6 @@
<?php <?php
require_once '../klein.php'; require_once '../Klein.php';
function title($x) { function title($x) {
return ucfirst($x); return ucfirst($x);
@ -8,11 +8,11 @@ function title($x) {
$tpl = new Klein('tempalte.html'); $tpl = new Klein('tempalte.html');
echo $tpl->render(array( echo $tpl->render([
'pagename' => 'awesome people', 'pagename' => 'awesome people',
'authors' => [['name' => 'Paul', 'age' => 10], ['name' => 'Jim', 'age' => 11], ['name' => 'Jane', 'age' => 12]], 'authors' => [['name' => 'Paul', 'age' => 10], ['name' => 'Jim', 'age' => 11], ['name' => 'Jane', 'age' => 12]],
'city'=> [ 'city'=> [
'Yaroslaval' => 1, 'Yaroslaval' => 1,
'Moscow' => 2 'Moscow' => 2
] ]
)); ]);

View file

@ -1,7 +1,7 @@
<?php <?php
$data = array ( $data = [
array ( [
'id' => 0, 'id' => 0,
'id_table' => 0, 'id_table' => 0,
'name' => '', 'name' => '',
@ -12,8 +12,8 @@ $data = array (
'row' => 0, 'row' => 0,
'position' => 0, 'position' => 0,
'type' => '', 'type' => '',
), ],
array ( [
'id' => 1, 'id' => 1,
'id_table' => 0, 'id_table' => 0,
'name' => '', 'name' => '',
@ -23,13 +23,12 @@ $data = array (
'row' => 0, 'row' => 0,
'position' => 1, 'position' => 1,
'type' => '', 'type' => '',
) ]
); ];
require_once '../klein.php'; require_once '../Klein.php';
$tpl = new Klein(); $tpl = new Klein('template2.html');
$tpl->compile('template2.html');
echo $tpl->render(array('content' => $data)); echo $tpl->render(['content' => $data]);

View file

@ -1,10 +1,9 @@
<?php <?php
$data = array('phedor', 'andrey'); $data = ['phedor', 'andrey'];
require_once '../klein.php'; require_once '../Klein.php';
$tpl = new Klein(); $tpl = new Klein('template3.html');
$tpl->compile('template3.html');
echo $tpl->render(array('names' => $data)); echo $tpl->render(['names' => $data]);

View file

@ -1,12 +1,12 @@
<?php <?php
require_once '../klein.php'; require_once '../Klein.php';
function title($x) { function title($x) {
return ucfirst($x); return ucfirst($x);
} }
$tpl = new Klein('tempalte.html'); $tpl = new Klein('template.html');
$u1 = new stdClass(); $u1 = new stdClass();
$u1->name = 'Paul'; $u1->name = 'Paul';
@ -20,11 +20,11 @@ $u3 = new stdClass();
$u3->name = 'Jane'; $u3->name = 'Jane';
$u3->age = 12; $u3->age = 12;
echo $tpl->render(array( echo $tpl->render([
'pagename' => 'awesome people', 'pagename' => 'awesome people',
'authors' => [$u1, $u2, $u3], 'authors' => [$u1, $u2, $u3],
'city'=> [ 'city'=> [
'Yaroslaval' => 1, 'Yaroslaval' => 1,
'Moscow' => 2 'Moscow' => 2
] ]
)); ]);

View file

@ -55,7 +55,7 @@
{% endmacro %} {% endmacro %}
<ul> <ul>
{% for user in users %} {% for user in users %}
{% hello(user) %} {{ hello(user) }}
{% endfor %} {% endfor %}
</ul> </ul>
``` ```