diff --git a/src/directives/utils.php b/src/directives/utils.php new file mode 100644 index 00000000..ae1a0c48 --- /dev/null +++ b/src/directives/utils.php @@ -0,0 +1,13 @@ + 0 && 'context' === $path[0] ) { + array_shift( $path ); + $result = $context; + foreach( $path as $key ) { + $result = $result[$key]; + } + } + return $result; +} \ No newline at end of file diff --git a/src/directives/wp-bind.php b/src/directives/wp-bind.php new file mode 100644 index 00000000..947e0148 --- /dev/null +++ b/src/directives/wp-bind.php @@ -0,0 +1,23 @@ +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 ); + } +} \ No newline at end of file diff --git a/src/directives/wp-context.php b/src/directives/wp-context.php new file mode 100644 index 00000000..6762b389 --- /dev/null +++ b/src/directives/wp-context.php @@ -0,0 +1,44 @@ +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 ); +} diff --git a/src/directives/wp-show.php b/src/directives/wp-show.php new file mode 100644 index 00000000..879e937c --- /dev/null +++ b/src/directives/wp-show.php @@ -0,0 +1,27 @@ +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( '' ); + } +} \ No newline at end of file