This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
function get_from_context( $expr, $context ) { | ||
$path = explode( '.', $expr ); | ||
if ( count( $path ) > 0 && 'context' === $path[0] ) { | ||
array_shift( $path ); | ||
$result = $context; | ||
foreach( $path as $key ) { | ||
$result = $result[$key]; | ||
} | ||
} | ||
return $result; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/utils.php'; | ||
|
||
function process_wp_bind( &$tags, &$context ) { | ||
if ( $tags->is_tag_closer() ) { | ||
return; | ||
} | ||
|
||
$prefixed_attributes = $tags->get_attributes_by_prefix( 'wp-bind:' ); | ||
|
||
foreach( $prefixed_attributes as $name => $expr ) { | ||
$attr_parts = explode( ':', $name ); | ||
if ( count( $attr_parts ) < 2 ) { | ||
continue; | ||
} | ||
$bound_attr = $attr_parts[1]; | ||
|
||
// TODO: Properly parse $value. | ||
$value = get_from_context( $expr, $context->get_context() ); | ||
$tags->set_attribute( $bound_attr, $value ); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
class WP_Directive_Context { | ||
protected $stack = array( array() ); | ||
|
||
function __construct( $context = array() ) { | ||
$this->set_context( $context ); | ||
} | ||
|
||
public function get_context() { | ||
return end( $this->stack ); | ||
} | ||
|
||
public function set_context( $context ) { | ||
array_push( $this->stack, array_replace_recursive( $this->get_context(), $context ) ); | ||
} | ||
|
||
public function rewind_context() { | ||
array_pop( $this->stack ); | ||
} | ||
} | ||
|
||
function process_wp_context( &$tags, &$context ) { | ||
if ( 'WP-CONTEXT' === $tags->get_tag() ) { | ||
if ( $tags->is_tag_closer() ) { | ||
$context->rewind_context(); | ||
return; | ||
} | ||
$value = $tags->get_attribute( 'data' ); | ||
} else { | ||
// TODO: Implement rewinding context upon matching closing tag. | ||
$value = $tags->get_attribute( 'wp-context' ); | ||
} | ||
|
||
if ( null === $value ) { | ||
// No wp-context directive. | ||
return; | ||
} | ||
|
||
$new_context = json_decode( $value, true ); | ||
// TODO: Error handling. | ||
|
||
$context->set_context( $new_context ); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/utils.php'; | ||
|
||
function process_wp_show( &$tags, &$context ) { | ||
if ( $tags->is_tag_closer() ) { | ||
return; | ||
} | ||
|
||
if ( 'WP-SHOW' === $tags->get_tag() ) { | ||
$value = $tags->get_attribute( 'when' ); | ||
} else { | ||
$value = $tags->get_attribute( 'wp-data' ); | ||
} | ||
|
||
if ( null === $value ) { | ||
return; | ||
} | ||
|
||
// TODO: Properly parse $value. | ||
$show = get_from_context( $value, $context->get_context() ); | ||
|
||
if( ! $show ) { | ||
// $content = $tags->get_content_inside_balanced_tags() | ||
// $tags->set_content_inside_balanced_tags( '<template>' . $content . '</template>' ); | ||
} | ||
} |