Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Brand New Antlers Engine ✨ #4257

Merged
merged 174 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
174 commits
Select commit Hold shift + click to select a range
7c67d3b
Implements an updated Antlers parser
JohnathonKoster Sep 13, 2021
6dd75d7
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Sep 13, 2021
1096959
Make StyleCI happy
JohnathonKoster Sep 13, 2021
1110e6d
Merge branch '3.2' of https://github.com/Stillat/cms into 3.2
JohnathonKoster Sep 13, 2021
010ef12
Removes errant dd call
JohnathonKoster Sep 13, 2021
7d3195f
Removes hard-coded ignition dependency, fixes namespaces on some tests
JohnathonKoster Sep 13, 2021
3c682ef
Ensures that a Parser instance is bound in IoC; L6, and L7 compatibil…
JohnathonKoster Sep 14, 2021
45871d8
Refactors for methods that are not worth failing tests
JohnathonKoster Sep 14, 2021
38c4efd
Removes test since isUuid no longer exists
JohnathonKoster Sep 14, 2021
b09ff47
Removes backslash for style
JohnathonKoster Sep 14, 2021
44f63f0
Makes current antlers defautl
JohnathonKoster Sep 14, 2021
fc986eb
Adds polyfill for mb_str_split function
JohnathonKoster Sep 14, 2021
b948ed3
Prevents loop data scope stomping
JohnathonKoster Sep 15, 2021
779ec62
Apply StyleCI changes
JohnathonKoster Sep 15, 2021
ca73ac8
No dump.
JohnathonKoster Sep 16, 2021
07e6260
Cleanup
JohnathonKoster Sep 16, 2021
8154035
Corrects an issue where nested double braces would confuse the optimi…
JohnathonKoster Sep 18, 2021
87845c2
Test that literal spans don't skipped when existing a skipped region
JohnathonKoster Sep 18, 2021
0977b4b
Apply changes from StyleCI
JohnathonKoster Sep 18, 2021
6aba8e7
Prevent `null` incoming paths from exploding runtime
JohnathonKoster Sep 19, 2021
b721146
Apply changes from StyleCI
JohnathonKoster Sep 19, 2021
0d8115a
Adds support for interpolations within variable references
JohnathonKoster Sep 26, 2021
0fe0501
Apply changes from StyleCI
JohnathonKoster Sep 26, 2021
b931a11
Use runtime parser as the default in tests
jasonvarga Oct 4, 2021
b629fce
Use regex parser in its test
jasonvarga Oct 4, 2021
6127e14
Add temporary class to dump tests for random issues
jasonvarga Oct 4, 2021
2bb9514
simplify by using the collection tag
jasonvarga Oct 4, 2021
719e07b
Uses runtime parser as default for internal tests
JohnathonKoster Oct 6, 2021
8e2df5c
Apply changes from StyleCI
JohnathonKoster Oct 6, 2021
df519e9
Simplifies some parameter content; adds test cases to ensure compatib…
JohnathonKoster Oct 7, 2021
ffcf17c
Apply changes from StyleCI
JohnathonKoster Oct 7, 2021
ccc1da7
Corrects runtime type labeler (with tests), adds a missing word in co…
JohnathonKoster Oct 8, 2021
348a5ec
Provides improvements to how modifier strings are parsed
JohnathonKoster Oct 8, 2021
eadb3b9
Apply changes from StyleCI
JohnathonKoster Oct 8, 2021
04968b0
Improves error reporting, and internal line offset management
JohnathonKoster Oct 8, 2021
4629687
Apply changes from StyleCI
JohnathonKoster Oct 8, 2021
db01ee2
Ensures consistent behavior with ModifierNotFoundExceptions; adds tem…
JohnathonKoster Oct 8, 2021
11620c3
Improvements to path cache performance
JohnathonKoster Oct 9, 2021
a9da6a5
Improves backwards compatibility by allowing vars as method names
JohnathonKoster Oct 9, 2021
89d4a9d
Apply changes from StyleCI
JohnathonKoster Oct 9, 2021
84ad60b
Expands test coverage to ensure equality comparisons are valid
JohnathonKoster Oct 10, 2021
28531fc
Apply changes from StyleCI
JohnathonKoster Oct 11, 2021
08c4bcf
Removes PHP stacktrace as the first entry when reporting Antlers errors
JohnathonKoster Oct 11, 2021
5e7abd9
Apply changes from StyleCI
JohnathonKoster Oct 11, 2021
b4d12a7
Ensures modifiers break on operator types
JohnathonKoster Oct 13, 2021
a1e317d
Apply changes from StyleCI
JohnathonKoster Oct 13, 2021
a284967
Removes arithmetic operators from the list that will break modifier c…
JohnathonKoster Oct 13, 2021
70591dc
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Oct 16, 2021
b13dda8
Removes symbolic list syntax
JohnathonKoster Oct 20, 2021
5f04eda
Restores PHP stack trace, while preserving partial include traces
JohnathonKoster Oct 20, 2021
95a6516
Refactors Logic group names for consistency
JohnathonKoster Oct 20, 2021
c49ba30
Removes duplicate EntryFactory
JohnathonKoster Oct 20, 2021
0b03b20
Corrects Factory namespace
JohnathonKoster Oct 20, 2021
1dbdd31
Allows for nested values on arrays when using group_by
JohnathonKoster Oct 20, 2021
6568572
Apply changes from StyleCI
JohnathonKoster Oct 20, 2021
75d4e8b
Removes limit to allow for compound variable names in groupby
JohnathonKoster Oct 20, 2021
17bf05d
Improves backwards compatibility; gives tags priority in more trivial…
JohnathonKoster Oct 20, 2021
a74a3f9
Removes newline for StyleCI
JohnathonKoster Oct 20, 2021
81f271e
couple of bugs
jasonvarga Oct 20, 2021
6648e1c
Corrects whitespace issues when handling internal content, and when r…
JohnathonKoster Oct 20, 2021
026fc6d
Corrects an issue where values were incorrectly converted while being…
JohnathonKoster Oct 22, 2021
10f707d
Apply changes for StyleCI
JohnathonKoster Oct 22, 2021
62d50b5
Expands test coverage to ensure that actual values are used within oe…
JohnathonKoster Oct 23, 2021
17820de
Cleanup
JohnathonKoster Oct 23, 2021
131d6c3
Apply changes for StyleCI
JohnathonKoster Oct 23, 2021
547c4db
Ensures empty collections are falsey
JohnathonKoster Oct 23, 2021
dd12cc2
Adds a test case to validate array style parameters work on multi par…
JohnathonKoster Oct 23, 2021
b0d6829
Apply changes for StyleCI
JohnathonKoster Oct 23, 2021
621cad0
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Oct 27, 2021
478d34d
Ensures collection-type objects don't get converted to strings in wei…
JohnathonKoster Oct 29, 2021
552308a
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Nov 5, 2021
e6d8401
Improves backwards compatibility with tight spacing in modifier param…
JohnathonKoster Nov 5, 2021
80a67ee
Make StyleCI happy
JohnathonKoster Nov 5, 2021
369df64
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Nov 9, 2021
13ecfff
Update to account for NL placement difference
JohnathonKoster Nov 9, 2021
11a240e
Corrects shorthand modifier raw behavior
JohnathonKoster Nov 11, 2021
c83a870
Adds test for shorthand raw modifier
JohnathonKoster Nov 11, 2021
6231f3d
Ensures consistent behavior with parameter-style modifiers, especiall…
JohnathonKoster Nov 12, 2021
bcc6957
Apply changes for StyleCI
JohnathonKoster Nov 12, 2021
94efaef
Ensures consistent behavior when arrays contain non-sequential numeri…
JohnathonKoster Nov 13, 2021
31957b7
Apply changes for StyleCI
JohnathonKoster Nov 13, 2021
7481a74
Corrects appended node reference
JohnathonKoster Nov 15, 2021
f946eb8
Correct comment
JohnathonKoster Nov 15, 2021
cffa529
Update PhpExecutionNode.php
JohnathonKoster Nov 15, 2021
b3f9a34
Revert "Update PhpExecutionNode.php"
JohnathonKoster Nov 15, 2021
1d5b595
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Nov 16, 2021
dc1c828
Corrects reported error
JohnathonKoster Nov 17, 2021
adceb4f
More error message updates
JohnathonKoster Nov 17, 2021
040bb0e
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Nov 17, 2021
8b4fec5
NL in loop differences
JohnathonKoster Nov 17, 2021
64df06e
Delete ajKxYB.diff
JohnathonKoster Nov 17, 2021
a40540a
Update GetErrorsTest.php
JohnathonKoster Nov 17, 2021
039e86a
Ensures that varRef is set to last element in token stack
JohnathonKoster Nov 17, 2021
2f62883
Cleanup; corrects node values
JohnathonKoster Nov 17, 2021
67153e8
Ensures that more than two simple modifier parameters can be supplied
JohnathonKoster Nov 21, 2021
d1b7588
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Dec 11, 2021
3a6a365
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Dec 19, 2021
a955bee
Ensures that the return value of `Value` is converted to an array, if…
JohnathonKoster Dec 19, 2021
4fb8eac
Removes unused import.
JohnathonKoster Dec 19, 2021
c60ebc1
Resets the runtime value cache each time a new Antlers context begins.
JohnathonKoster Dec 19, 2021
bda197f
String quality of life improvements
JohnathonKoster Dec 26, 2021
c5cc7b9
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Dec 26, 2021
f127564
Corrects test values
JohnathonKoster Dec 26, 2021
e9d3b22
Allows empty strings to be incremented using the addition assignment …
JohnathonKoster Dec 26, 2021
58b7410
Adds linter note
JohnathonKoster Dec 31, 2021
86e00e3
Apply changes for StyleCI
JohnathonKoster Dec 31, 2021
a588acf
Fix test so that it works all the time
JohnathonKoster Dec 31, 2021
746bfe0
Consistent casing between methods with Noparse
JohnathonKoster Jan 5, 2022
4a5b356
Limit the number of items for each collection in this test
JohnathonKoster Jan 5, 2022
430a16b
Simplifies some data access techniques; corrects issues with T_LOGIC_…
JohnathonKoster Jan 6, 2022
37bc192
Apply changes for StyleCI
JohnathonKoster Jan 6, 2022
7d9828b
Ensures unless/elseunless transformations are not processed by the No…
JohnathonKoster Jan 8, 2022
84aaae5
Applies changes for StyleCI
JohnathonKoster Jan 8, 2022
ae4a440
Merge branch 'statamic:3.2' into 3.2
JohnathonKoster Jan 8, 2022
fb5f8b3
Implements method-style syntax for modifiers, allows Antlers PHP node…
JohnathonKoster Jan 13, 2022
a18362f
The Great Simplification (removes autoboxing & libraries)
JohnathonKoster Jan 14, 2022
3ec8c7d
Apply changes for StyleCI
JohnathonKoster Jan 14, 2022
08e05a1
Removes library manager binding
JohnathonKoster Jan 14, 2022
0c6b358
Some post-library removal cleanup
JohnathonKoster Jan 14, 2022
ccdf759
Apply changes for StyleCI
JohnathonKoster Jan 14, 2022
d48fbe5
Adds a flag when evaluating method-style modifiers to allow implement…
JohnathonKoster Jan 15, 2022
b14efb4
Adds support for bracket ([]) array initializer syntax
JohnathonKoster Jan 15, 2022
7c1575c
Apply changes for StyleCI
JohnathonKoster Jan 15, 2022
0d4b9f8
Adds support for the .= string concatenation style.
JohnathonKoster Jan 15, 2022
49d34a4
Corrects regression when string concat is used in non-variable contexts
JohnathonKoster Jan 15, 2022
f07d610
Apply changes for StyleCI
JohnathonKoster Jan 15, 2022
14cf012
Clean up statement from debugging
JohnathonKoster Jan 16, 2022
d922214
Makes groupby syntax more approachable by reusing the orderby syntax …
JohnathonKoster Jan 19, 2022
a51529f
Applies changes for StyleCI
JohnathonKoster Jan 19, 2022
eb6112c
Various improvements, tweaks, and cleanup
JohnathonKoster Jan 20, 2022
b9155c7
Apply changes for StyleCI
JohnathonKoster Jan 20, 2022
fcab0de
Defers evaluating group truthiness until the very end to make arrays/…
JohnathonKoster Jan 21, 2022
6fbfa19
Update ConditionalsTest.php
JohnathonKoster Jan 21, 2022
bb84a8b
Applies changes for StyleCI
JohnathonKoster Jan 21, 2022
aea3c84
Various improvements, bug fixes, syntax tweaks, cleanup
JohnathonKoster Jan 21, 2022
52dd1a9
Applies changes for StyleCI
JohnathonKoster Jan 21, 2022
dd6150f
Adds coverage for explode modifier under different scenarios; ensures…
JohnathonKoster Jan 22, 2022
0b81245
Applies changes for StyleCI
JohnathonKoster Jan 22, 2022
93192ce
Improves performance on tags that return arrays
JohnathonKoster Jan 22, 2022
294e5db
Applies changes for StyleCI
JohnathonKoster Jan 22, 2022
e0a7304
Improves performance by caching document fragments; additional cleanu…
JohnathonKoster Jan 23, 2022
da14674
Applies changes for StyleCI
JohnathonKoster Jan 23, 2022
3a3a41b
Docs, adds way to set a cache entry without knowing the original cont…
JohnathonKoster Jan 23, 2022
c8287c2
Defers runtime assignment processing until after the loop iteration t…
JohnathonKoster Jan 23, 2022
0b1417a
Applies changes for StyleCI
JohnathonKoster Jan 23, 2022
534465f
Adds test coverage for starts_with and special characters #5128
JohnathonKoster Jan 25, 2022
b720de7
Supports parameters starting with "@"
JohnathonKoster Jan 28, 2022
932819c
Updates test date to match upstream
JohnathonKoster Feb 2, 2022
af8666e
Adds a new PHP node variant, adds more test coverage
JohnathonKoster Feb 2, 2022
1a9b854
Applies changes for StyleCI
JohnathonKoster Feb 2, 2022
57dbc67
Corrects test whitespace, makes test_antlers_php_node test name uniqu…
JohnathonKoster Feb 2, 2022
d543707
Merge branch 'master' into pr/JohnathonKoster/4257
jasonvarga Feb 9, 2022
079f908
Conditional 'get from context' modifier logic
jasonvarga Feb 10, 2022
d999864
Consolidate parser tests into a trait used by the old and new parsers…
jasonvarga Feb 11, 2022
dd3278f
styleci
jasonvarga Feb 11, 2022
09ea5ef
Provides parity with query Builder instances; tweaks to deferred Augm…
JohnathonKoster Feb 11, 2022
63f5d05
Applies changes for StyleCI
JohnathonKoster Feb 11, 2022
a3c2995
Makes working with fieldset prefixes a bit easier in Antlers
JohnathonKoster Feb 16, 2022
d48eb75
Applies changes for StyleCI
JohnathonKoster Feb 17, 2022
6762555
Provides a way to conditionally not send a parameter value
JohnathonKoster Feb 17, 2022
fb154f1
Applies changes for StyleCI
JohnathonKoster Feb 17, 2022
1926267
Merge branch 'master' into pr/JohnathonKoster/4257
jasonvarga Feb 18, 2022
bff22c2
have the parsertestcase extend our base testcase
jasonvarga Feb 18, 2022
9b7cb84
Rename/move ParserContract to Parser
jasonvarga Feb 18, 2022
d794763
Move into existing provider
jasonvarga Feb 18, 2022
e83c195
publish antlers config file
jasonvarga Feb 18, 2022
f52b15c
rework bindings ...
jasonvarga Feb 18, 2022
3abc6a4
use contract, so that the new parser will be used
jasonvarga Feb 18, 2022
bdd1c40
styleci
jasonvarga Feb 18, 2022
efcc6d7
use testbench 6.7.0 which has the define-env annotation support
jasonvarga Feb 18, 2022
694e031
remove 7.4 polyfill
jasonvarga Feb 18, 2022
b956002
Split engine tests into parser specific ones, and moved a regex speci…
jasonvarga Feb 18, 2022
010c9e5
Corrects PHP enabled behavior when there are no Antlers tags in the d…
JohnathonKoster Feb 18, 2022
96aa63d
Merge branch '3.2' of https://github.com/Stillat/cms into 3.2
JohnathonKoster Feb 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"fakerphp/faker": "~1.10",
"google/cloud-translate": "^1.6",
"mockery/mockery": "^1.2.3",
"orchestra/testbench": "^4.0 || ^5.0 || ^6.0"
"orchestra/testbench": "^4.0 || ^5.0 || ^6.7.0"
},
"config": {
"optimize-autoloader": true,
Expand Down
60 changes: 60 additions & 0 deletions config/antlers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Version
|--------------------------------------------------------------------------
|
| The desired Antlers language version to utilize. Possibly values are:
| - regex: Utilize pre-3.3 Antlers. Appropriate for existing sites.
| - runtime: Utilizes >= 3.3 Antlers, recommended for new sites.
|
*/

'version' => 'regex',

/*
|--------------------------------------------------------------------------
| Guarded Variables
|--------------------------------------------------------------------------
|
| Any variable pattern that appears in this list will not be allowed
| in any Antlers template, including any user-supplied values.
|
*/

'guardedVariables' => [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain when/why you might want to use this? (and the tag/modifier equivalents)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thinking/driving-force behind that feature was configurable enforcement/restriction of data on sites where there may be many authors. Site administrators can add items to those lists to prevent Control Panel users from using Live Preview on a field with antlers: true from getting data they shouldn't be able to, as well as prevent authors from using certain tags/modifiers/variables entirely, separate from the actual template files.

'config.app.key',
],

/*
|--------------------------------------------------------------------------
| Guarded Tags
|--------------------------------------------------------------------------
|
| Any tag pattern that appears in this list will not be allowed
| in any Antlers template, including any user-supplied values.
|
*/

'guardedTags' => [

],

/*
|--------------------------------------------------------------------------
| Guarded Modifiers
|--------------------------------------------------------------------------
|
| Any modifier pattern that appears in this list will not be allowed
| in any Antlers template, including any user-supplied values.
|
*/

'guardedModifiers' => [

],

];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment has nothing to do with this line, I'm just putting it here so we can have a discussion thread.

I've found an issue regarding passing values into partials. I wasn't even sure how to write a test for it, so I've created a repo so you can see it. The bug is explained in the readme.

https://github.com/jasonvarga/statamic-runtime-parser-testing

Copy link
Contributor Author

@JohnathonKoster JohnathonKoster Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! To test this, I've created two new convert library methods that will return either the name of a class, or the data type of a variable. These are:

{{ convert:className(variable_name) }}
{{ convert:typeOf(variable_name) }}

If the asset gets incorrectly converted to an array anywhere as it's being passed into the partials (or any other tag or modifier), className will throw an error since it's expecting an object, which will cause the test as a whole to fail.

To help test this, I also created new partials inside tests/__fixtures__/views:

  • example.antlers.html
  • nested_one.antlers.html
  • nested_two.antlers.html
  • nested_three.antlers.html
  • nested_four.antlers.html

Each partial will output the class name of the expected image. nested_two will call nested_three, and override the image value to an integer set pulled from it's view matter. nested_three outputs both the image, and that integer value before calling nested_four while setting image back to the original asset.

This test case was placed in tests/Antlers/Runtime/Fieldtypes/AssetTemplateTest.php as test_parameter_values_are_not_lost_when_passed_into_tags. There is probably a better place for it, but didn't want to copy all of the test asset container setup.

78 changes: 78 additions & 0 deletions src/Contracts/View/Antlers/Parser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Statamic\Contracts\View\Antlers;

use Statamic\View\Antlers\AntlersString;

interface Parser
{
/**
* Parses the text.
*
* @param string $text Text to parse
* @param array|object $data Array or object to use
* @return AntlersString
*/
public function parse($text, $data = []);

/**
* Ignore tags-who-must-not-be-parsed.
*
* @param string $text The text to extract from
* @return string
*/
public function extractNoparse($text);

/**
* Sets whether or not PHP code should be evaluated.
*
* @param bool $allow Whether PHP is allowed.
* @return Parser
*/
public function allowPhp($allow = true);

/**
* Parses a view file.
*
* @param string $view The view path.
* @param string $text The view contents.
* @param array $data The data.
* @return AntlersString
*/
public function parseView($view, $text, $data = []);

/**
* Injects noparse extractions.
*
* This is so that multiple parses can store noparse
* extractions and all noparse can then be injected right
* before data is displayed.
*
* @param string $text Text to inject into
* @return string
*/
public function injectNoparse($text);

public function valueWithNoparse($text);

/**
* Takes a scope-notated key and finds the value for it in the given
* array or object.
*
* @param string $key Dot-notated key to find
* @param array|object $data Array or object to search
* @param mixed $default Default value to use if not found
* @return mixed
*/
public function getVariable($key, $context, $default = null);

/**
* Sets a render callback.
*
* @param $callback
* @return Parser
*/
public function callback($callback);

public function cascade($cascade);
}
4 changes: 2 additions & 2 deletions src/Fields/Value.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use IteratorAggregate;
use JsonSerializable;
use Statamic\Contracts\Data\Augmentable;
use Statamic\Contracts\View\Antlers\Parser;
use Statamic\Support\Str;
use Statamic\View\Antlers\Parser;

class Value implements IteratorAggregate, JsonSerializable
{
Expand Down Expand Up @@ -90,7 +90,7 @@ public function antlersValue(Parser $parser, $variables)
}

if (Str::contains($value, '{')) {
return $parser->extractNoparse(str_replace('{{', '@{{', $value));
return $parser->valueWithNoparse($value);
}

return $value;
Expand Down
Loading