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

Commit e4228c1

Browse files
committed
Extract expression parser
1 parent 8334591 commit e4228c1

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/directives/utils.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
function get_from_context( $expr, $context ) {
4+
$path = explode( '.', $expr );
5+
if ( count( $path ) > 0 && 'context' === $path[0] ) {
6+
array_shift( $path );
7+
$result = $context;
8+
foreach( $path as $key ) {
9+
$result = $result[$key];
10+
}
11+
}
12+
return $result;
13+
}

src/directives/wp-show.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
<?php
22

3+
require_once __DIR__ . '/utils.php';
4+
35
function process_wp_show( &$tags, &$context ) {
46
if ( 'WP-SHOW' === $tags->get_tag() ) {
57
$value = $tags->get_attribute( 'when' );
68
} else {
79
$value = $tags->get_attribute( 'wp-data' );
810
}
911

10-
if ( null !== $value ) {
11-
// TODO: Properly parse $value.
12-
$path = explode( '.', $value );
13-
if ( count( $path ) > 0 && 'context' === $path[0] ) {
14-
array_shift( $path );
15-
$show = $context;
16-
foreach( $path as $key ) {
17-
$show = $show[$key];
18-
}
19-
}
12+
if ( null === $value ) {
13+
return;
14+
}
15+
16+
// TODO: Properly parse $value.
17+
$show = get_from_context( $value, $context );
2018

21-
if( ! $show ) {
22-
// $content = $tags->get_content_inside_balanced_tags()
23-
// $tags->set_content_inside_balanced_tags( '<template>' . $content . '</template>' );
24-
}
19+
if( ! $show ) {
20+
// $content = $tags->get_content_inside_balanced_tags()
21+
// $tags->set_content_inside_balanced_tags( '<template>' . $content . '</template>' );
2522
}
2623
}

0 commit comments

Comments
 (0)