-
Notifications
You must be signed in to change notification settings - Fork 10
SSR: Add wp-show
attribute directive processor
#141
Conversation
e4f2c2a
to
ce06fd2
Compare
ed41813
to
9dd3e0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All those directives are neat!
Per #152 (comment), I'll update this PR to turn the |
2d886ff
to
f40ae17
Compare
I'm considering removing the We could then rewrite the directive like so: diff --git a/src/directives/attributes/wp-show.php b/src/directives/attributes/wp-show.php
index 89ed612..82b28cc 100644
--- a/src/directives/attributes/wp-show.php
+++ b/src/directives/attributes/wp-show.php
@@ -3,25 +3,19 @@
require_once __DIR__ . '/../utils.php';
function process_wp_show( $tags, $context ) {
- if ( ! $tags->is_tag_closer() ) { // TODO: Exclude void and self-closing!
- set_bookmark_for_directive( $tags, 'wp-show' );
+ if ( $tags->is_tag_closer() ) {
return;
}
- $end = 'wp-show-closer';
- $tags->set_bookmark( 'wp-show-closer' );
- $start = seek_bookmark_for_directive( $tags, 'wp-show' );
-
$value = $tags->get_attribute( 'wp-show' );
- if ( null !== $value ) {
- $show = evaluate( $value, $context->get_context() );
+ if ( null === $value ) {
+ return;
+ }
- if ( ! $show ) {
- $content = $tags->get_content_inside_bookmarks( $start, $end );
- $tags->set_content_inside_bookmarks( $start, $end, '<template>' . $content . '</template>' );
- }
+ $show = evaluate( $value, $context->get_context() );
+ if ( ! $show ) {
+ $content = $tags->get_inner_html();
+ echo $content;
+ $tags->set_inner_html( '<template>' . $content . '</template>' );
}
- $tags->seek( $end );
- $tags->release_bookmark( $start );
- $tags->release_bookmark( $end );
}
|
is there any foreseeable need for |
Not having From this: <div data-wp-show="false" class="my-class">
<p>Children</p>
</div> Doing this: $p->set_outter_html( '<template>' . $p->get_outter_html() . '</template>' ); <template>
<div data-wp-show="false" class="my-class">
<p>Children</p>
</div>
</template> Instead of this: $p->set_inner_html( '<template>' . $p->get_inner_html() . '</template>' ); <div data-wp-show="false" class="my-class">
<template>
<p>Children</p>
</template>
</div> We haven't decided about it yet, but yesterday I shared an example of something that (I think) would not be possible with the This case could work with a "wrap tag" API as well, if that would make things easier. It would also leave some leftovers when using For example, this code: <table wp-slot="data"></table>
<template wp-fill="data">
<tr>
<td wp-text="id"></td>
<td wp-text="firstName"></td>
<td wp-text="lastName"></td>
</tr>
</template> Would end up as this using <table wp-slot="data">
<tr>
<td wp-text="id"></td>
<td wp-text="firstName"></td>
<td wp-text="lastName"></td>
</tr>
</table>
<template wp-fill="data"></template> Leaving the empty template hanging around, but it doesn't affect the page. This case could work with a "remove tag" API as well, if that would make things easier. The rest of the core directives we have in mind right now don't seem to need anything similar to So at this moment, it depends on what we decide for |
Not sure if you meant this, but I suggested a new approach to handle |
It makes sense indeed. I've answered you on the other issue: |
Rebased on #169. |
We've decided that we'd like
I.e. we'd like the server-side rendered <template>
<div data-wp-show="false" class="my-class">
<p>Children</p>
</div>
</template> (with Our directive processor (#169) currently doesn't support As a consequence, I'd like to try implementing a |
This reverts commit b7c6925.
This reverts commit 16faac9.
Co-authored-by: Greg Ziółkowski <[email protected]>
Co-authored-by: Greg Ziółkowski <[email protected]>
This reverts commit 9430be8.
I'm going to close this issue as part of the migration to the Gutenberg repository. This task was added to the Roadmap and we'll open a new issue/discussion once it's time to start working on this again. |
Implement the
data-wp-show
directive, which is supposed to transform code likeinto
per this discussion. (For truthy values of
data-wp-show
, it does not modify the HTML at all.)Note that the behavior to move the
data-wp-show
attribute from the wrapped tag to the wrapping one was implemented in da195d7. If we decide that we'd rather keep the attribute on the wrapped tag, we can simply revert that commit.