Merge branch 'origin/master'

Conflicts:
	CHANGELOG.md
	docs/tags/raw.md
	src/Fenom/Compiler.php
	src/Fenom/Render.php
	src/Fenom/Template.php
This commit is contained in:
Ivan Shalganov 2014-04-10 00:11:04 +04:00
commit 654b259b42
7 changed files with 31 additions and 16 deletions

View File

@ -1,7 +1,7 @@
Changelog Changelog
========= =========
## 1.5.0 ## 2.0.0
- Add tag filter - Add tag filter
- Redesign `extends` algorithm - Redesign `extends` algorithm
@ -12,6 +12,11 @@ Changelog
- Move benchmark to another project - Move benchmark to another project
- Rename `\Fenom\Compiler` to `\Fenom\Tags` - Rename `\Fenom\Compiler` to `\Fenom\Tags`
### 1.4.9 (2013-04-09)
- Fix #75
- Docs++
### 1.4.8 (2013-12-01) ### 1.4.8 (2013-12-01)
- Fix #52 - Fix #52

View File

@ -20,7 +20,15 @@ Tag {macro} [RU]
{macro.plus x=$num y=100} {macro.plus x=$num y=100}
``` ```
На данный момент рекурсивный вызов макроса не поддерживается. Во время рекурсивного вызова используйте суффикс macro что бы обратиться к текущему макросу:
```smarty
{macro plus(x, y, z=0)}
...
{macro.plus x=2 y=4}
...
{/macro}
```
### {import} ### {import}

View File

@ -22,7 +22,7 @@ For functions use tag with prefix `raw:`:
{autoescape true} {autoescape true}
... ...
{my_func page=5} {* escape *} {my_func page=5} {* escape *}
{raw:my_func page=5} {* unescape *} {my_func:raw page=5} {* unescape *}
... ...
{/autoescate} {/autoescate}
``` ```

View File

@ -3,31 +3,31 @@ Basic usage
### Initialize Fenom ### Initialize Fenom
Use factory method Creating an object via factory method
```php ```php
$fenom = Fenom::factory('/path/to/templates', '/path/to/compiled/template', $options); $fenom = Fenom::factory('/path/to/templates', '/path/to/compiled/template', $options);
``` ```
Use `new` operator Creating an object via `new` operator
```php ```php
$fenom = new Fenom(new Provider('/path/to/templates')); $fenom = new Fenom(new Provider('/path/to/templates'));
$fenom->setCompileDir('/path/to/template/cache'); $fenom->setCompileDir('/path/to/template/cache');
$fenom->setOptions($options); $fenom->setOptions($options);
``` ```
### Render template ### Rendering template
Output template Output template
```php ```php
$fenom->display("template/name.tpl", $vars); $fenom->display("template/name.tpl", $vars);
``` ```
Get template into the variable Get the result of rendering the template
```php ```php
$result = $fenom->fetch("template/name.tpl", $vars); $result = $fenom->fetch("template/name.tpl", $vars);
``` ```
Create pipe-line into callback Create the pipeline of rendering into callback
```php ```php
$fenom->pipe( $fenom->pipe(
"template/sitemap.tpl", "template/sitemap.tpl",

View File

@ -976,4 +976,4 @@ class Compiler
$scope->tpl->escape = $scope["escape"]; $scope->tpl->escape = $scope["escape"];
} }
} }

View File

@ -214,7 +214,6 @@ class Render extends \ArrayObject
*/ */
public function display(array $values) public function display(array $values)
{ {
// $this->exchangeArray($values);
$this->_code->__invoke($values, $this); $this->_code->__invoke($values, $this);
return $values; return $values;
} }

View File

@ -571,11 +571,11 @@ class Template extends Render
return $this->out($this->parseExpr($tokens), $tokens); return $this->out($this->parseExpr($tokens), $tokens);
} }
} catch (InvalidUsageException $e) { } catch (InvalidUsageException $e) {
throw new CompileException($e->getMessage() . " in {$this} line {$this->_line}", 0, E_ERROR, $this->_name, $this->_line, $e); throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}", 0, E_ERROR, $this->_name, $this->_line, $e);
} catch (\LogicException $e) { } catch (\LogicException $e) {
throw new SecurityException($e->getMessage() . " in {$this} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e); throw new SecurityException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
} catch (\Exception $e) { } catch (\Exception $e) {
throw new CompileException($e->getMessage() . " in {$this} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e); throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e);
} }
} }
@ -1282,7 +1282,7 @@ class Template extends Render
} }
if (!is_string($mods)) { // dynamic modifier if (!is_string($mods)) { // dynamic modifier
$mods = 'call_user_func($tpl->getStorage()->getModifier("' . $mods . '"), '; $mods = 'call_user_func($tpl->getStorage()->getModifier("' . $modifier . '"), ';
} else { } else {
$mods .= "("; $mods .= "(";
} }
@ -1353,6 +1353,7 @@ class Template extends Render
$macro = false; $macro = false;
if (isset($this->macros[$name])) { if (isset($this->macros[$name])) {
$macro = $this->macros[$name]; $macro = $this->macros[$name];
$recursive = $macro['recursive'];
} else { } else {
foreach ($this->_stack as $scope) { foreach ($this->_stack as $scope) {
if ($scope->name == 'macro' && $scope['name'] == $name) { // invoke recursive if ($scope->name == 'macro' && $scope['name'] == $name) { // invoke recursive
@ -1378,8 +1379,10 @@ class Template extends Render
} }
} }
if ($recursive) { if ($recursive) {
$recursive['recursive'] = true; $body = '$tpl->getMacro("' . $name . '")->__invoke($tpl);';
return '$tpl->getMacro("' . $name . '")->__invoke(' . Compiler::toArray($args) . ', $tpl);'; if($recursive instanceof Scope) {
$recursive['recursive'] = true;
}
} else { } else {
$vars = $this->tmpVar(); $vars = $this->tmpVar();
return $vars . ' = $var; $var = ' . Compiler::toArray($args) . ';' . PHP_EOL . '?>' . return $vars . ' = $var; $var = ' . Compiler::toArray($args) . ';' . PHP_EOL . '?>' .