Skip to content

Commit

Permalink
version 2.0.5 - adds === and !==
Browse files Browse the repository at this point in the history
  • Loading branch information
marionnewlevant committed Aug 24, 2018
1 parent 6e43960 commit 5f680c3
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Twig Perversion Changelog

## 2.0.5 - 2018.08.24
### Added
* Added `===`, and `!==` operators.

## 2.0.4 - 2018.07.16
### Added
* Added `string`, `float`, `int`, and `bool` typecast filters.
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Making twig do things it really shouldn't. Twig is not intended to be a general purpose programming language, and there are some things that really don't belong in the language. This plugin adds a few of those things anyway.

- `{% break %}`, `{% continue %}`, and `{% return %}` tags
- `===` and `!==` operators
- `is numeric` test
- `json_decode` filter
- `array_splice` filter
Expand Down Expand Up @@ -57,6 +58,11 @@ or

A macro with a `{% return %}` tag will return whatever the return value is (which can be a complex expression). Any other output generated by the macro will be discarded.

### Operators
- **===** and **!==**

Compares two values for equivalence, using php's `===` and `!==` operators.

### Tests
- **Numeric**

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "marionnewlevant/twig-perversion",
"description": "Making twig do things it really shouldn't",
"version": "2.0.4",
"version": "2.0.5",
"type": "craft-plugin",
"keywords": [
"craft", "craftcms", "plugin", "twigperversion"
Expand Down
11 changes: 11 additions & 0 deletions src/twigextensions/Expression_Binary_Equivalent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace marionnewlevant\twigperversion\twigextensions;

class Expression_Binary_Equivalent extends \Twig_Node_Expression_Binary
{
public function operator(\Twig_Compiler $compiler)
{
return $compiler->raw('===');
}
}
11 changes: 11 additions & 0 deletions src/twigextensions/Expression_Binary_NotEquivalent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace marionnewlevant\twigperversion\twigextensions;

class Expression_Binary_NotEquivalent extends \Twig_Node_Expression_Binary
{
public function operator(\Twig_Compiler $compiler)
{
return $compiler->raw('!==');
}
}
19 changes: 19 additions & 0 deletions src/twigextensions/TwigPerversionTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ public function getFilters()
];
}

public function getOperators()
{
return [
[],
[
'===' => [
'precedence' => 20,
'class' => '\marionnewlevant\twigperversion\twigextensions\Expression_Binary_Equivalent',
'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT,
],
'!==' => [
'precedence' => 20,
'class' => '\marionnewlevant\twigperversion\twigextensions\Expression_Binary_NotEquivalent',
'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT,
],
],
];
}

/**
* Cast value as a string.
*
Expand Down

0 comments on commit 5f680c3

Please sign in to comment.