Skip to content

Commit

Permalink
better error message for #95
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordius Chen committed Jul 23, 2014
1 parent a4a680f commit 4f036af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/lightncandy.php
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ protected static function scanFeatures($token, &$context) {
}

if (!isset($vars[0])) {
return static::noNamedArguments($token, $context, true);
return static::noNamedArguments($token, $context, true, ', you should use it after a custom helper.');
}

if ($vars[0] !== 'else') {
Expand Down Expand Up @@ -1445,9 +1445,9 @@ protected static function scanFeatures($token, &$context) {
* @param array $context current compile context
* @param boolean $named is named arguments
*/
public static function noNamedArguments($token, &$context, $named) {
public static function noNamedArguments($token, &$context, $named, $suggest = '!') {
if ($named) {
$context['error'][] = 'Do not support name=value in ' . static::tokenString($token) . '!';
$context['error'][] = 'Do not support name=value in ' . static::tokenString($token) . $suggest;
}
}

Expand Down Expand Up @@ -1542,7 +1542,7 @@ public static function compileToken(&$token, &$context) {
return $ret;
}

static::noNamedArguments($token, $context, $named);
static::noNamedArguments($token, $context, $named, ', maybe you missing the custom helper?');

return static::compileVariable($context, $vars, $raw);
}
Expand Down Expand Up @@ -1600,7 +1600,7 @@ protected static function compileSection(&$token, &$context, &$vars, $named) {
if ($r) {
return $r;
}
static::noNamedArguments($token, $context, $named);
static::noNamedArguments($token, $context, $named, ', maybe you missing the block custom helper?');
return static::compileBlockBegin($context, $vars);
}
}
Expand Down
12 changes: 11 additions & 1 deletion tests/errorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,17 @@ public function errorProvider()
Array(
'template' => '{{a=b}}',
'options' => Array('flags' => LightnCandy::FLAG_NAMEDARG),
'expected' => 'Do not support name=value in {{a=b}}!',
'expected' => 'Do not support name=value in {{a=b}}, you should use it after a custom helper.',
),
Array(
'template' => '{{test a=b}}',
'options' => Array('flags' => LightnCandy::FLAG_NAMEDARG),
'expected' => 'Do not support name=value in {{test a=b}}, maybe you missing the custom helper?',
),
Array(
'template' => '{{#test a=b}}YA~{{/test}}',
'options' => Array('flags' => LightnCandy::FLAG_NAMEDARG),
'expected' => 'Do not support name=value in {{#test a=b}}, maybe you missing the block custom helper?',
),
Array(
'template' => '{{#foo}}1{{^}}2{{/foo}}',
Expand Down

0 comments on commit 4f036af

Please sign in to comment.