This repository was archived by the owner on Jul 28, 2023. It is now read-only.
Implement wp-context attribute directive#143
Merged
ockham merged 2 commits intomain-wp-directives-pluginfrom Feb 9, 2023
Merged
Implement wp-context attribute directive#143ockham merged 2 commits intomain-wp-directives-pluginfrom
wp-context attribute directive#143ockham merged 2 commits intomain-wp-directives-pluginfrom
Conversation
luisherranz
approved these changes
Feb 2, 2023
Collaborator
Author
|
Thank you for reviewing, @luisherranz!
FWIW, |
This was referenced Feb 9, 2023
ockham
added a commit
that referenced
this pull request
Feb 15, 2023
Some attribute directives (such as `wp-context`, see #143), need to be run not only on an opening tag (e.g. `<div wp-context="...">` but also on the matching closing one. (For `wp-context`, this is required to reset the context to the value that corresponds to the enclosing scope's context.) This needs somewhat complex logic to keep track of nested tags. Consider e.g. the following example (used in this PR's unit test): ```html <div>Example: <div foo-test="abc"> <img> <span>This is a test></span> <div>Here is a nested div</div> </div> </div> ``` Here, we want to run the `foo-test` attribute directive processor on the closing `</div>` that matches the opening `<div foo-test="abc">` -- but not on any of the other two closing `</div>`s. Rather than requiring individual directive processors to implement the required tracking of nested tags, we implement it in the `wp_process_directives` function. To that end, this commit also moves it into a separate file and changes its signature a bit for better testability. Finally, we're adding a unit test to verify the behavior described above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add the
wp-contextattribute directive (which we had previously only implemented as a tag directive).While handling the closing tag will require quite a bit of complex logic, I now think that that logic should go into the
wp_process_directivesloop rather than the individual directive processor.