From f11b9b3e562df848e5ba1be6f4d2c0651f3beb38 Mon Sep 17 00:00:00 2001 From: andrey Date: Wed, 29 Mar 2017 10:34:59 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D0=BE=D0=B5?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20=D1=81=D0=BB=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D1=87=D0=B0=D1=81=D1=82=D1=8C=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Klein.php | 8 +------- examples/example.php | 6 +++--- examples/example2.php | 19 +++++++++---------- examples/example3.php | 9 ++++----- examples/example4.php | 8 ++++---- examples/{tempalte.html => template.html} | 0 readme.md | 2 +- 7 files changed, 22 insertions(+), 30 deletions(-) rename examples/{tempalte.html => template.html} (100%) diff --git a/Klein.php b/Klein.php index 3526fd7..b424c22 100644 --- a/Klein.php +++ b/Klein.php @@ -3,13 +3,7 @@ class Klein { public $code; - function __construct($html = null) { - if ($html) { - $this->compile($html); - } - } - - function compile($html) { + function _construct($html) { $pattern = array_map(function ($grammar) { list(, $result) = $grammar; $body = strtr($grammar[0], [' ' => "\s*", '+' => "\s+", ':var' => "(\w+(\s*\.\s*\w+)*)", ':id' => "(\w+)", '{{' => "{{\!?"]); diff --git a/examples/example.php b/examples/example.php index e92e336..0d481cc 100644 --- a/examples/example.php +++ b/examples/example.php @@ -1,6 +1,6 @@ render(array( +echo $tpl->render([ 'pagename' => 'awesome people', 'authors' => [['name' => 'Paul', 'age' => 10], ['name' => 'Jim', 'age' => 11], ['name' => 'Jane', 'age' => 12]], 'city'=> [ 'Yaroslaval' => 1, 'Moscow' => 2 ] -)); \ No newline at end of file +]); \ No newline at end of file diff --git a/examples/example2.php b/examples/example2.php index 326f5e3..82077fe 100644 --- a/examples/example2.php +++ b/examples/example2.php @@ -1,7 +1,7 @@ 0, 'id_table' => 0, 'name' => '', @@ -12,8 +12,8 @@ $data = array ( 'row' => 0, 'position' => 0, 'type' => '', - ), - array ( + ], + [ 'id' => 1, 'id_table' => 0, 'name' => '', @@ -23,13 +23,12 @@ $data = array ( 'row' => 0, 'position' => 1, 'type' => '', - ) -); + ] +]; -require_once '../klein.php'; +require_once '../Klein.php'; -$tpl = new Klein(); -$tpl->compile('template2.html'); +$tpl = new Klein('template2.html'); -echo $tpl->render(array('content' => $data)); +echo $tpl->render(['content' => $data]); diff --git a/examples/example3.php b/examples/example3.php index 2189a2e..dd71fd4 100644 --- a/examples/example3.php +++ b/examples/example3.php @@ -1,10 +1,9 @@ compile('template3.html'); +$tpl = new Klein('template3.html'); -echo $tpl->render(array('names' => $data)); +echo $tpl->render(['names' => $data]); diff --git a/examples/example4.php b/examples/example4.php index 5e1f739..f7cc60e 100644 --- a/examples/example4.php +++ b/examples/example4.php @@ -1,12 +1,12 @@ name = 'Paul'; @@ -20,11 +20,11 @@ $u3 = new stdClass(); $u3->name = 'Jane'; $u3->age = 12; -echo $tpl->render(array( +echo $tpl->render([ 'pagename' => 'awesome people', 'authors' => [$u1, $u2, $u3], 'city'=> [ 'Yaroslaval' => 1, 'Moscow' => 2 ] -)); \ No newline at end of file +]); \ No newline at end of file diff --git a/examples/tempalte.html b/examples/template.html similarity index 100% rename from examples/tempalte.html rename to examples/template.html diff --git a/readme.md b/readme.md index e81d102..9423c28 100644 --- a/readme.md +++ b/readme.md @@ -55,7 +55,7 @@ {% endmacro %} ``` \ No newline at end of file