Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Blunt but effective
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Apr 25, 2023
1 parent 5f3e155 commit 3dbff3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
17 changes: 17 additions & 0 deletions phpunit/directives/attributes/wp-show.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,23 @@ public function test_directive_wraps_content_in_template_if_when_is_false() {
$this->assertSame( $context_before->get_context(), $context->get_context(), 'data-wp-show directive changed context' );
}

public function test_directive_does_not_wrap_template_in_template() {
$markup = '<template data-wp-show="context.myblock.open">I should not be shown!</template>';

$tags = new WP_Directive_Processor( $markup );
$tags->next_tag();

$context_before = new WP_Directive_Context( array( 'myblock' => array( 'open' => false ) ) );
$context = clone $context_before;
process_wp_show( $tags, $context );

$tags->next_tag( array( 'tag_closers' => 'visit' ) );
process_wp_show( $tags, $context );

$this->assertSame( $markup, $tags->get_updated_html() );
$this->assertSame( $context_before->get_context(), $context->get_context(), 'data-wp-show directive changed context' );
}

public function test_directive_wraps_content_preceded_by_other_html_in_template_if_when_is_false() {
$markup = '<p>Some text</p><div data-wp-show="context.myblock.open">I should not be shown!</div>';

Expand Down
4 changes: 4 additions & 0 deletions src/directives/attributes/wp-show.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ function process_wp_show( $tags, $context ) {
return;
}

if ( 'TEMPLATE' === $tags->get_tag() ) {
return; // Don't wrap a `<template>` in a `<template>`.
}

$wrapper_bookmark = $tags->wrap_in_tag( 'TEMPLATE' );
$tags->seek( $wrapper_bookmark );
$tags->set_attribute( 'data-wp-show', $value );
Expand Down

0 comments on commit 3dbff3f

Please sign in to comment.