From 3cfc3d548766c7654180187baf20c5df197c5a33 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Sun, 18 May 2014 00:32:34 +0400 Subject: [PATCH 01/18] Update README.md Fix urls --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 087c319..1610d24 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Fenom - Template Engine for PHP > For old version: `{"fenom/fenom": "1.*"}`. [List](https://github.com/bzick/fenom/wiki/Migrate-from-1.*-to-2.*) of incompatibilities between 1.* and 2.* versions. [![Latest Stable Version](https://poser.pugx.org/fenom/fenom/v/stable.png)](https://packagist.org/packages/fenom/fenom) -[![Build Status](https://travis-ci.org/bzick/fenom.svg?branch=develop)](https://travis-ci.org/bzick/fenom) -[![Coverage Status](https://coveralls.io/repos/bzick/fenom/badge.png?branch=develop)](https://coveralls.io/r/bzick/fenom?branch=master) +[![Build Status](https://travis-ci.org/bzick/fenom.svg?branch=master)](https://travis-ci.org/bzick/fenom) +[![Coverage Status](https://coveralls.io/repos/bzick/fenom/badge.png?branch=master)](https://coveralls.io/r/bzick/fenom?branch=master) [![Total Downloads](https://poser.pugx.org/fenom/fenom/downloads.png)](https://packagist.org/packages/fenom/fenom) ## [Quick start](./docs/start.md) :: [Documentation](./docs/readme.md) :: [Benchmark](./docs/benchmark.md) From 9f3b3b861bd236acc40bfe9a8927a003735ea289 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Mon, 19 May 2014 09:52:50 +0400 Subject: [PATCH 02/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1610d24..335685f 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Fenom - Template Engine for PHP =============================== > Composer [package](https://packagist.org/packages/fenom/fenom): `{"fenom/fenom": "2.*"}`.
-> For old version: `{"fenom/fenom": "1.*"}`. [List](https://github.com/bzick/fenom/wiki/Migrate-from-1.*-to-2.*) of incompatibilities between 1.* and 2.* versions. +> For old version: `{"fenom/fenom": "1.*"}`. [List](https://github.com/bzick/fenom/wiki/Migrate-from-1.4.9-to-2.0) of incompatibilities between 1.* and 2.* versions. [![Latest Stable Version](https://poser.pugx.org/fenom/fenom/v/stable.png)](https://packagist.org/packages/fenom/fenom) [![Build Status](https://travis-ci.org/bzick/fenom.svg?branch=master)](https://travis-ci.org/bzick/fenom) From 5c2b10e1cb17b8124f2855239c87ee4332e0f2ac Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Mon, 19 May 2014 10:13:29 +0400 Subject: [PATCH 03/18] Update syntax.md --- docs/syntax.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/syntax.md b/docs/syntax.md index 6775aff..cfd917f 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -32,7 +32,7 @@ Example outputs next HTML code: ``` `{$user.id}` and `{$user['id']}` are same: ```smarty - + ``` В случае объекта, доступ к его свойствам осущесвляется так как и в PHP — через оператор `->`: From a324d176b9e3ae489f550e2ce6f6a3b324d19fa7 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Mon, 19 May 2014 10:15:00 +0400 Subject: [PATCH 04/18] Update readme.md --- docs/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/readme.md b/docs/readme.md index 8bd3640..3009957 100644 --- a/docs/readme.md +++ b/docs/readme.md @@ -9,7 +9,7 @@ Documentation * [Usage](./start.md#install-fenom) * [Framework adapters](./adapters.md) * [For developers](./dev/readme.md) -* [Configuration](./settings.md) +* [Configuration](./configuration.md) * [Syntax](./syntax.md) * [Operators](./operators.md) From 83e1e7177eddcfabbcaf62d6412740cfa5694da1 Mon Sep 17 00:00:00 2001 From: Dmitry Kulagin Date: Mon, 19 May 2014 20:32:27 +0300 Subject: [PATCH 05/18] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=B8=D0=BC=D1=8F=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fenom::STRIP на Fenom::AUTO_STRIP --- docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 54a2420..cf8e17d 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -34,7 +34,7 @@ Options may by associative array like `'option_name' => true` or bitwise mask. | *force_verify* | `Fenom::FORCE_VERIFY` | check existence every used variable | decreases performance | | *disable_statics* | `Fenom::DENY_STATICS` | disable calling static methods in templates. | | -| *strip* | `Fenom::STRIP` | strip all whitespaces in templates. | decrease cache size | +| *strip* | `Fenom::AUTO_STRIP` | strip all whitespaces in templates. | decrease cache size | ```php $fenom->setOptions(array( From f6c4da8297a9297512e4da9abfe0488d6746d04e Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Fri, 6 Jun 2014 10:27:06 +0400 Subject: [PATCH 06/18] Update dev docs --- docs/dev/readme.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/dev/readme.md b/docs/dev/readme.md index c097f37..4e96964 100644 --- a/docs/dev/readme.md +++ b/docs/dev/readme.md @@ -3,4 +3,10 @@ Develop If you want to discuss the enhancement of the Fenom, create an issue on Github or submit a pull request. +There tho branches — master and develop. +The branch master for stable releases and hotfixes; the branch develop for development of features. Each tag names by rule `major.minor.fix` (1.4.9, 1.1.2 etc) and creates from master. Version changes by the rule of [semantic versioning](http://semver.org/). + For questions: a.cobest@gmail.com (English, Russian languages) + + +* the [scheme of work](schema.md) From f3de50813e15d9c106993f7dddebfed165457344 Mon Sep 17 00:00:00 2001 From: bzick Date: Sun, 8 Jun 2014 23:50:43 +0400 Subject: [PATCH 07/18] Fix '~=' operator --- src/Fenom/Template.php | 21 +++++++++++++-------- tests/cases/Fenom/TemplateTest.php | 2 ++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index a2aca54..1682522 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -724,16 +724,21 @@ class Template extends Render break; } } elseif ($tokens->is('~')) { // string concatenation operator: 'asd' ~ $var - $concat = array(array_pop($exp)); - while ($tokens->is('~')) { - $tokens->next(); - if ($tokens->is(T_LNUMBER, T_DNUMBER)) { - $concat[] = "strval(" . $this->parseTerm($tokens) . ")"; - } else { - $concat[] = $this->parseTerm($tokens); + if($tokens->isNext('=')) { // ~= + $exp[] = ".="; + $tokens->next()->next(); + } else { + $concat = array(array_pop($exp)); + while ($tokens->is('~')) { + $tokens->next(); + if ($tokens->is(T_LNUMBER, T_DNUMBER)) { + $concat[] = "strval(" . $this->parseTerm($tokens) . ")"; + } else { + $concat[] = $this->parseTerm($tokens); + } } + $exp[] = "(" . implode(".", $concat) . ")"; } - $exp[] = "(" . implode(".", $concat) . ")"; } else { break; } diff --git a/tests/cases/Fenom/TemplateTest.php b/tests/cases/Fenom/TemplateTest.php index b9ff1d2..36500b5 100644 --- a/tests/cases/Fenom/TemplateTest.php +++ b/tests/cases/Fenom/TemplateTest.php @@ -1170,6 +1170,7 @@ class TemplateTest extends TestCase array('{"string" ~ ++$one ~ "end"}', "string2end"), array('{"string" ~ "one" ~ "end"}', "stringoneend"), array('{"string" ~ 1 ~ "end"}', "string1end"), + array('{$one ~= "string"} is {$one}', "1string is 1string"), ); } @@ -1536,6 +1537,7 @@ class TemplateTest extends TestCase /** * @dataProvider providerConcat + * @group testConcat */ public function testConcat($code, $result) { From ad9a601b9f96255a4e4d70be8f60bab4c89582ac Mon Sep 17 00:00:00 2001 From: bzick Date: Mon, 9 Jun 2014 23:40:31 +0400 Subject: [PATCH 08/18] 2.0.1 --- CHANGELOG.md | 9 ++++++++- docs/helpme.md | 9 +++++++++ docs/tags/ignore.md | 12 ++++++++---- docs/tags/include.md | 15 ++++++++------- sandbox/fenom.php | 8 +------- sandbox/templates/concat-bug.tpl | 2 ++ src/Fenom/Template.php | 8 +++++++- 7 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 docs/helpme.md create mode 100644 sandbox/templates/concat-bug.tpl diff --git a/CHANGELOG.md b/CHANGELOG.md index 4893020..1a13a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,14 @@ Changelog ========= -## 2.0.0RC1 +## 2.0.1 + +- Fix string concatenation. If `~` in the end of expression Fenom generates broken template. +- Fix `~=` operator. Operator was not working. +- Tests++ +- Docs++ + +## 2.0.0 - Add tag the {filter} - Redesign `extends` algorithm: diff --git a/docs/helpme.md b/docs/helpme.md new file mode 100644 index 0000000..c553994 --- /dev/null +++ b/docs/helpme.md @@ -0,0 +1,9 @@ +Требуется помощь в переводе документации +======================================== + +Принимаю любую помощь в переводе статей документации. Вносить правки в документацию можете любым удобным: + +* Сделать merge request (нажав `Edit` ввержу файла) +* Прислать адресс статьи и что на что заменить. В письме лучше укажите `Fenom docs`. + +Заранее благодарен! \ No newline at end of file diff --git a/docs/tags/ignore.md b/docs/tags/ignore.md index d6ec197..f80860d 100644 --- a/docs/tags/ignore.md +++ b/docs/tags/ignore.md @@ -1,7 +1,9 @@ -Tag {ignore} [RU] -================= +Tag {ignore} +============ -Тег {ignore} позволяет отключить парсер на фрагмент шаблона, таким образом все фигурные скобки в блоке будут проигнорированы. +{ignore} tags allow a block of data to be taken literally. +This is typically used around Javascript or stylesheet blocks where {curly braces} would interfere with the template delimiter syntax. +Anything within {ignore}{/ignore} tags is not interpreted, but displayed as-is. ```smarty {ignore} @@ -9,7 +11,9 @@ Tag {ignore} [RU] {/ignore} ``` -You may ignore delimiters without tag `{ignore}` +{ignore} tags are normally not necessary, as Fenom ignores delimiters that are surrounded by whitespace. +Be sure your javascript and CSS curly braces are surrounded by whitespace: + ```smarty var data = { "time": obj.ts }; ``` \ No newline at end of file diff --git a/docs/tags/include.md b/docs/tags/include.md index 2c7d678..50a68d7 100644 --- a/docs/tags/include.md +++ b/docs/tags/include.md @@ -1,5 +1,5 @@ -Tag {include} [RU] -================== +Tag {include} +============= `{include}` tags are used for including other templates in the current template. Any variables available in the current template are also available within the included template. @@ -7,20 +7,21 @@ Tag {include} [RU] {include "about.tpl"} ``` -Переменные для подключаемого шаблона можно переопределить, задавая их аргументами тега. +If you need to set yours variables for template list them in attributes. ```smarty {include "about.tpl" page=$item limit=50} ``` -Все изменения переменных в подключаемом шаблоне не будут воздействовать на родительский шаблон. +All variables changed in child template has no affect to variables in parent template. ### {insert} The tag insert template code instead self. -* No dynamic name allowed -* No variables as attribute allowed +* No dynamic name allowed. +* No variables as attribute allowed. +* Increase performance because insert code as is in compilation time. For example, main.tpl: @@ -36,7 +37,7 @@ b.tpl: b: {$b} ``` -Во время разбора шаблона код шаблона `b.tpl` будет вставлен в код шаблона `main.tpl` как есть: +Code of `b.tpl` will be inserted into `main.tpl` as is: ```smarty a: {$a} diff --git a/sandbox/fenom.php b/sandbox/fenom.php index 26843eb..e76845b 100644 --- a/sandbox/fenom.php +++ b/sandbox/fenom.php @@ -15,11 +15,5 @@ namespace { $fenom = Fenom::factory(__DIR__.'/templates', __DIR__.'/compiled', Fenom::FORCE_COMPILE); - $fenom->display("extends/75-child.tpl", array( - "user" => array( - "name" => "Ivka", - 'type' => 'new' - ), - 'type' => 'new' - )); + var_dump($fenom->compile("concat-bug.tpl", false)->getBody()); } \ No newline at end of file diff --git a/sandbox/templates/concat-bug.tpl b/sandbox/templates/concat-bug.tpl new file mode 100644 index 0000000..4f9fa48 --- /dev/null +++ b/sandbox/templates/concat-bug.tpl @@ -0,0 +1,2 @@ +Some eval: +{$dop_content = ": some texta"} \ No newline at end of file diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index 1682522..edff568 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -379,6 +379,9 @@ class Template extends Render } } + /** + * @param $tag_name + */ public function ignore($tag_name) { $this->_ignore = $tag_name; } @@ -729,12 +732,15 @@ class Template extends Render $tokens->next()->next(); } else { $concat = array(array_pop($exp)); + while ($tokens->is('~')) { $tokens->next(); if ($tokens->is(T_LNUMBER, T_DNUMBER)) { $concat[] = "strval(" . $this->parseTerm($tokens) . ")"; } else { - $concat[] = $this->parseTerm($tokens); + if(!$concat[] = $this->parseTerm($tokens)) { + throw new UnexpectedTokenException($tokens); + } } } $exp[] = "(" . implode(".", $concat) . ")"; From 926ce77b5a672c2550e14b56407837db98bf2e40 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Mon, 9 Jun 2014 23:52:44 +0400 Subject: [PATCH 09/18] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a13a23..1e21f82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ Changelog ========= -## 2.0.1 +### 2.0.1 (2013-06-09) - Fix string concatenation. If `~` in the end of expression Fenom generates broken template. - Fix `~=` operator. Operator was not working. From 17d9f385c452aee7f9dbaa4c813a8b9f1a1a9b12 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Mon, 9 Jun 2014 23:53:26 +0400 Subject: [PATCH 10/18] Update helpme.md --- docs/helpme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/helpme.md b/docs/helpme.md index c553994..611b078 100644 --- a/docs/helpme.md +++ b/docs/helpme.md @@ -1,9 +1,9 @@ Требуется помощь в переводе документации ======================================== -Принимаю любую помощь в переводе статей документации. Вносить правки в документацию можете любым удобным: +Принимаю любую помощь в переводе статей документации. Вносить правки в документацию можете любым удобным способом: * Сделать merge request (нажав `Edit` ввержу файла) * Прислать адресс статьи и что на что заменить. В письме лучше укажите `Fenom docs`. -Заранее благодарен! \ No newline at end of file +Заранее благодарен! From 7c7b820326fe2590443cd4e97aa161c01567be8b Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Sat, 14 Jun 2014 01:11:45 +0400 Subject: [PATCH 11/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 335685f..0c770f5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Fenom - Template Engine for PHP **Fenom** *(from "fenomenal")* — lightweight template engine for PHP. -It mean: +It means: * Known Smarty-like [syntax](./docs/syntax.md) with improvements. * Very [fast](./docs/benchmark.md). From dacbbf32a76d3143f6d7e4bb55d943b89ad4e2f2 Mon Sep 17 00:00:00 2001 From: Ivan Shalganov Date: Sat, 14 Jun 2014 01:13:22 +0400 Subject: [PATCH 12/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c770f5..3681c53 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ It means: * Very [flexible](./docs/configuration.md#extends). * Progressive parser without regular expressions. * High [code coverage](https://coveralls.io/r/bzick/fenom?branch=master). -* Easy to understand [how it works](./docs/dev.md). +* Easy to understand [how it works](./docs/dev/readme.md). * Easy to [use](./docs/start.md). * Maximum [protection](./docs/configuration.md#configure). From 8a3dbf1ffa025518e344392f2ea81494fd115b65 Mon Sep 17 00:00:00 2001 From: bzick Date: Wed, 18 Jun 2014 17:21:29 +0400 Subject: [PATCH 13/18] Update docs --- docs/configuration.md | 36 +-------- docs/ext/extend.md | 163 +++++++++++++++++++++++++++++++++++++++++ docs/operators.md | 4 +- docs/readme.md | 64 +++++++++------- src/Fenom/Provider.php | 1 - 5 files changed, 205 insertions(+), 63 deletions(-) create mode 100644 docs/ext/extend.md diff --git a/docs/configuration.md b/docs/configuration.md index cf8e17d..83bed60 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -50,46 +50,12 @@ By default all options disabled ## Extends -### Template providers [TRANSLATE] +### Template providers Бывает так что шаблны не хранятся на файловой сиситеме, а хранятся в некотором хранилище, например, в базе данных MySQL. В этом случае шаблонизатору нужно описать как забирать шаблоны из хранилища, как проверять дату изменения шаблона и где хранить кеш шаблонов (опционально). Эту задачу берут на себя Providers, это объекты реальзующие интерфейс `Fenom\ProviderInterface`. -### Cache providers [TRANSLATE] - -Изначально Fenom не расчитывался на то что кеш скомпиленых шаблонов может располагаться не на файловой системе. -Однако, в теории, есть возможность реализовать свое кеширование для скомпиленых шаблонов без переопределения шаблонизатора. -Речь идет о своем протоколе, отличным от `file://`, который [можно определить](http://php.net/manual/en/class.streamwrapper.php) в PHP. - -Ваш протол должени иметь класс реализации протокола как указан в документации [Stream Wrapper](http://www.php.net/manual/en/class.streamwrapper.php). -Класс протокола может иметь не все указанные в документации методы. Вот список методов, необходимых шаблонизатору: - -* [CacheStreamWrapper::stream_open](http://www.php.net/manual/en/streamwrapper.stream-open.php) -* [CacheStreamWrapper::stream_write](http://www.php.net/manual/en/streamwrapper.stream-write.php) -* [CacheStreamWrapper::stream_close](http://www.php.net/manual/en/streamwrapper.stream-close.php) -* [CacheStreamWrapper::rename](http://www.php.net/manual/en/streamwrapper.rename.php) - -For `include`: - -* [CacheStreamWrapper::stream_stat](http://www.php.net/manual/en/streamwrapper.stream-stat.php) -* [CacheStreamWrapper::stream_read](http://www.php.net/manual/en/streamwrapper.stream-read.php) -* [CacheStreamWrapper::stream_eof](http://www.php.net/manual/en/streamwrapper.stream-eof.php) - -**Note** -(On 2014-05-13) Zend OpCacher doesn't support custom protocols except `file://` and `phar://`. - -For example, - -```php -$this->setCacheDir("redis://hash/compiled/"); -``` - -* `$cache = fopen("redis://hash/compiled/XnsbfeDnrd.php", "w");` -* `fwrite($cache, "...