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 %}