Merge pull request #131 from bzick/develop

small fixes
This commit is contained in:
Ivan Shalganov 2015-01-07 17:42:58 +03:00
commit e4a7a07107
5 changed files with 18 additions and 27 deletions

View File

@ -405,9 +405,6 @@ class Fenom
$this->_provider = $provider; $this->_provider = $provider;
} }
public function setCachePerms() {
}
/** /**
* Set compile directory * Set compile directory
* *

View File

@ -9,11 +9,9 @@
*/ */
namespace Fenom; namespace Fenom;
use Doctrine\Instantiator\Exception\InvalidArgumentException;
use Fenom\Error\InvalidUsageException; use Fenom\Error\InvalidUsageException;
use Fenom\Error\UnexpectedTokenException; use Fenom\Error\UnexpectedTokenException;
use Fenom\Tokenizer;
use Fenom\Template;
use Fenom\Scope;
/** /**
* Compilers collection * Compilers collection
@ -116,7 +114,7 @@ class Compiler
* @param Tag $scope * @param Tag $scope
* @return string * @return string
*/ */
public static function tagElse(Tokenizer $tokens, Tag $scope) public static function tagElse($tokens, Tag $scope)
{ {
$scope["else"] = true; $scope["else"] = true;
return '} else {'; return '} else {';
@ -247,8 +245,8 @@ class Compiler
"last" => false, "last" => false,
"step" => 1, "step" => 1,
"to" => false, "to" => false,
"max" => false, // "max" => false,
"min" => false // "min" => false
); );
$scope["after"] = $before = $body = array(); $scope["after"] = $before = $body = array();
$i = array('', ''); $i = array('', '');
@ -312,7 +310,7 @@ class Compiler
* @param Tag $scope * @param Tag $scope
* @return string * @return string
*/ */
public static function forElse(Tokenizer $tokens, Tag $scope) public static function forElse($tokens, Tag $scope)
{ {
$scope["no-break"] = $scope["no-continue"] = true; $scope["no-break"] = $scope["no-continue"] = true;
$scope["else"] = true; $scope["else"] = true;
@ -436,7 +434,7 @@ class Compiler
* @param Tag $scope * @param Tag $scope
* @return string * @return string
*/ */
public static function switchClose(Tokenizer $tokens, Tag $scope) public static function switchClose($tokens, Tag $scope)
{ {
self::_caseResort($scope); self::_caseResort($scope);
$expr = $scope["var"]; $expr = $scope["var"];
@ -776,7 +774,7 @@ class Compiler
* @param Tag $scope * @param Tag $scope
* @return string * @return string
*/ */
public static function setClose(Tokenizer $tokens, Tag $scope) public static function setClose($tokens, Tag $scope)
{ {
return $scope["name"] . '=' . $scope["value"] . ';'; return $scope["name"] . '=' . $scope["value"] . ';';
} }
@ -787,7 +785,7 @@ class Compiler
* @param Tag $scope * @param Tag $scope
* @return string * @return string
*/ */
public static function filterOpen(Tokenizer $tokens, Tag $scope) public static function filterOpen($tokens, Tag $scope)
{ {
$scope["filter"] = $scope->tpl->parseModifier($tokens, "ob_get_clean()"); $scope["filter"] = $scope->tpl->parseModifier($tokens, "ob_get_clean()");
return "ob_start();"; return "ob_start();";
@ -962,7 +960,7 @@ class Compiler
* @param Tokenizer $tokens * @param Tokenizer $tokens
* @param Tag $scope * @param Tag $scope
*/ */
public static function macroClose(Tokenizer $tokens, Tag $scope) public static function macroClose($tokens, Tag $scope)
{ {
if ($scope["recursive"]) { if ($scope["recursive"]) {
$scope["macro"]["recursive"] = true; $scope["macro"]["recursive"] = true;
@ -1017,7 +1015,7 @@ class Compiler
* @param Tokenizer $tokens * @param Tokenizer $tokens
* @param Tag $tag * @param Tag $tag
*/ */
public static function ignoreOpen(Tokenizer $tokens, Tag $tag) public static function ignoreOpen($tokens, Tag $tag)
{ {
$tag->tpl->ignore('ignore'); $tag->tpl->ignore('ignore');
} }

View File

@ -1467,13 +1467,13 @@ class Template extends Render
if ($tokens->is(Tokenizer::MACRO_STRING)) { if ($tokens->is(Tokenizer::MACRO_STRING)) {
$key = $tokens->getAndNext(); $key = $tokens->getAndNext();
if ($defaults && !isset($defaults[$key])) { if ($defaults && !isset($defaults[$key])) {
throw new \Exception("Unknown parameter '$key'"); throw new InvalidUsageException("Unknown parameter '$key'");
} }
if ($tokens->is("=")) { if ($tokens->is("=")) {
$tokens->next(); $tokens->next();
$params[$key] = $this->parseExpr($tokens); $params[$key] = $this->parseExpr($tokens);
} else { } else {
$params[$key] = 'true'; throw new InvalidUsageException("Invalid value for parameter '$key'");
} }
} elseif ($tokens->is(Tokenizer::MACRO_SCALAR, '"', T_VARIABLE, "[", '(')) { } elseif ($tokens->is(Tokenizer::MACRO_SCALAR, '"', T_VARIABLE, "[", '(')) {
$params[] = $this->parseExpr($tokens); $params[] = $this->parseExpr($tokens);

View File

@ -8,14 +8,13 @@ class SandboxTest extends TestCase {
public function test() public function test()
{ {
// $this->assertEquals([1, 2, 4, "as" => 767, "df" => ["qert"]], [1, 2, 4, "as" => 767, "df" => ["qet"]]); // $this->assertEquals([1, 2, 4, "as" => 767, "df" => ["qert"]], [1, 2, 4, "as" => 767, "df" => ["qet"]]);
// $this->fenom->addBlockCompiler('php', 'Fenom\Compiler::nope', function ($tokens, Tag $tag) { // $this->fenom->addBlockCompiler('php', 'Fenom\Compiler::nope', function ($tokens, Tag $tag) {
// return '<?php ' . $tag->cutContent(); // return '<?php ' . $tag->cutContent();
// }); // });
// $this->tpl('welcome.tpl', '{$a}'); // $this->tpl('welcome.tpl', '{$a}');
// try { // try {
// var_dump($this->fenom->compileCode('{$.fetch("welcome.tpl", ["a" => 1])}')->getBody()); // var_dump($this->fenom->compileCode('{for $i=0 to 3} {/for}')->getBody());
// } catch (\Exception $e) { // } catch (\Exception $e) {
// print_r($e->getMessage() . "\n" . $e->getTraceAsString()); // print_r($e->getMessage() . "\n" . $e->getTraceAsString());
// while ($e->getPrevious()) { // while ($e->getPrevious()) {

View File

@ -5,15 +5,12 @@ namespace Fenom;
class TagsTest extends TestCase class TagsTest extends TestCase
{ {
/**
public function _testSandbox() * @group test-for
*/
public function testFor()
{ {
try { $this->assertRender('{for $i=0 to=3}{$i},{/for}', "0,1,2,3,");
var_dump($this->fenom->compileCode("{var \$a=12313}\nVar: {\$a}")->getBody());
} catch (\Exception $e) {
echo "$e";
}
exit;
} }
/** /**