-
-
Notifications
You must be signed in to change notification settings - Fork 542
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
Conversation
Epic. |
…ity changes Removes a few str library methods that are not worth backporting
Insane but so welcome. ❤️ |
You’re my personal hero 🦸♂️ , this is epic! |
How will this affect performance? |
I personally haven't benchmarked it yet but apparently there's a huge improvement. |
For the vast majority of situations the parsing time is negligible now. As Jason mentioned, there will need to be benchmarks done :) There are numerous things going on under the hood to help optimize performance:
Of course, the same advice holds as always to help improve performance:
Hard numbers are difficult to throw around since it also depends on the execution environment, but on the limited number of complex sites that have been tested during development, a positive improvement has been seen. Undoubtedly there will be room for improvement :) tl;dr: The compiled PHP from Blade will still win, but new Antlers gets very close to those speeds when sticking to the language features. The performance cost of actually getting your page's data and assets will be the bottleneck in the vast majority of cases. There will also be new tooling available within the runtime itself, and the VS Code extension that will allow developers to see how much time each block of code is contributing to the total runtime :) |
That sounds very promising, as we have a quite entry and asset heavy site - I'm still in the process of migrating from v2, but any performance improvements are welcome :) |
Wow. Just wow. Is this 4.0 time already? |
Ensures left part of a condition manifests a collapsible type
…zed document parser
Exciting 🤩 |
@JohnathonKoster Ignore the test failures for now - I'm working on those still. |
Co-authored-by: Jack McDade <jack@jackmcdade.com>
… ... - Changed method names to the /** @test */ with snake case syntax - Inconsistencies regardling extra newlines in one parser vs the other are resolved by creating an assertion that collapses multiple newlines into single ones. We don't really care about the exact whitespace. - New parser uses renderString() instead of Antlers::parse(). Just went with that. - Added some missing tests that were added to the old parser but not applied to the new parser - Fixed some typos
Alright the tests are updated. Now our old ParserTest and your new TemplateTest will both use the exact same tests, they are shared through a trait. Now there are a handful of failures throughout the entire suite, and they're all for the same reason: #5238 The parser should be able to handle There's a few new tests in |
Sounds great! Thanks for getting the tests consolidated. I will take care of the failing items later this evening my time :) |
Provides a new handle_prefix parameter that will be applied to all variable lookups within the scope tag and the partial tag. These calls can be nested, and the first one that matches a variable is what is returned. If no prefixed match is found, normal/default variable handling behavior is then used, and then the normal Cascade logic is used. 🎉 ``` {{# Dynamically adding a trailing _ #}} {{ scope :handle_prefix="prefix ?= prefix + '_'" }} {{ title }} {{ /scope }} {{# Hardcoded prefix in a partial tag #}} {{ partial:partial-name handle_prefix="prefix_" }} ```
When the `void` value is resolved by the Runtime, that parameter is skipped and not sent to the tag.
- register both parsers regardless of which one is configured. they're not instantiated until called anyway. - work out which one to use for the Parser contract within the binding closure - the config will be ready by then. e.g. for within tests. - add tests, especially to check that injecting the old Parser class still works. (like the comment in ViewServiceProvider mentioned)
🥁 ... |
YES! 🚀 Been following this for a long time now. How will you celebrate this epic moment? |
@jackmcdade the new docs state Could someone elaborate what exactly this means? I'm a big fan of it myself, for example, when syntax-related things are more opinionated. So it doesn't matter whoever writes the Code in the end it will be very similiar - this leads to better readability and therefore better maintainability. This is one of the reasons the programming language Go was designed with very few keywords, so it's as simple as possible but of course still flexible enough to accomplish any task. If "more things Just Work" means there are less bugs and discrepancies it's a good thing, of course! |
The easiest way I can think to explain the "more forgiving matching engine" is something like this:
The updated engine would match those two pairs correctly, while the current engine may produce output similar to |
This PR provides a complete rewrite of the Antlers parser to separate it into two pieces:
Important Note: While some new Antlers features look like PHP, Antlers is still not PHP :)
Issues Accounted For
This PR resolves, or makes improvements for, the following issues:
|
#4249 - ensure_right doesn't work with|
Developers may use shorthand syntax to supply the vertical pipe as an argument:
{{ title | ensure_right:"|" }}
Developers utilizing parameter-style modifiers will still need to use the HTML entity version:
{{ title ensure_right=" |" }}
||
seen as modifier in some casewhere
doesn't work on terms #3636 -where
doesn't work on terms{{ select_var:label }}
is not workingAny tag/expression can be returned from an Antlers sub-expression. The
{{ title translate="{site:short_locale}" }}
syntax will work, but the variable reference will not.{{ if {collection:count in="collection_name" taxonomy:year="2019"} > 0}}
throws an error when taxonomy condition is added{{ if (collection == "pages") && (parent:slug != "home") }}
causes error??
instead ofor
causes form tag parser weirdness #3835 - Using??
instead ofor
causes form tag parser weirdnessThese two are now equivalent:
{ foo || 'contact' }
and{ foo or 'contact' }
old
variable with dynamic key #3514 - Can't useold
variable with dynamic keyFor 3097, the syntax should preferentially use single-braces inside the tag, but double braces will technically work here:
Adds test coverage for #2529 (Can't use modifiers in array syntax). Cannot repro in current 3.2 branch, however.
Cannot reproduce #4993 with Runtime parser. Partial tag receives expected parameters.
Ideas Implemented
Partial:
partials/_card.antlers.html
:Other code:
user:can
should be a conditional ideas#479 -user:can
should be a conditionalAny Antlers tag/expression can now be used in a condition (even if has spaces, or HTML-like parameters):
{{ articles = {collection:articles} }}
{{ data = {my_tag_pair_data} }}
Backwards Compatibility
There are some instances where backwards compatibility has been broken (Antlers tags nested inside other tags, and anything that is currently taking advantage of parser bugs).
Great care has been taken to break as little as possible, but accounting for every possible scenario in the wild is not possible. Because of this, existing Antlers has not been removed, and can be used on existing projects.
Creating Variables
This PR allows developers to create variables within Antlers:
Sub-expression/interpolated regions can also be assigned to variables:
Creating Arrays
Developers may create arrays within Antlers if they want to (although getting them from a view model, view composer, etc. is still preferred):
Associative arrays are also supported:
Calling Methods
Developers may now call methods on objects using the
{{ VARNAME:METHOD_NAME() }}
syntax:Developers may also pass arguments to methods:
Additional Improvements
{}
single brace sub-expressions (interpolations) as well as nested parenthesis is now deterministic{{ myarray | length /}}
once
tag-like to ensure that a part of a template only executes onceUpgrading/Downgrading
By default, all existing sites and all new sites will continue to use the regex Antlers parser.
To upgrade, set the
statamic.antlers.version
configuration option toruntime
.In
config/statamic/antlers.php
:To downgrade to "legacy" Antlers, set the value to
regex
(new default):In
config/statamic/antlers.php
: