diff --git a/ng-appserver/src/main/java/ng/appserver/templating/NGTemplateParserProxy.java b/ng-appserver/src/main/java/ng/appserver/templating/NGTemplateParserProxy.java index 2cc318b1..46432e2f 100644 --- a/ng-appserver/src/main/java/ng/appserver/templating/NGTemplateParserProxy.java +++ b/ng-appserver/src/main/java/ng/appserver/templating/NGTemplateParserProxy.java @@ -50,29 +50,34 @@ public NGElement parse() throws NGDeclarationFormatException, NGHTMLFormatExcept private static NGElement toDynamicElement( final PNode node ) { return switch( node ) { - case PBasicNode n -> toDynamicElement( n.tag() ); + case PBasicNode n -> toDynamicElement( n ); case PGroupNode n -> toTemplate( n.children() ); case PHTMLNode n -> new NGHTMLBareString( n.value() ); case PCommentNode n -> new NGHTMLCommentString( n.value() ); }; } - private static NGElement toDynamicElement( final NGDynamicHTMLTag tag ) { + private static NGElement toDynamicElement( final PBasicNode node ) { + + final String type = node.type(); + final Map associations = associationsFromDeclaration( node.bindings(), node.isInline() ); + final NGElement childTemplate = toTemplate( node.children() ); + try { - return NGApplication.dynamicElementWithName( tag.declaration().type(), associationsFromDeclaration( tag.declaration() ), toTemplate( tag.childrenWithStringsProcessedAndCombined() ), Collections.emptyList() ); + return NGApplication.dynamicElementWithName( type, associations, childTemplate, Collections.emptyList() ); } catch( NGElementNotFoundException e ) { // FIXME: Experimental functionality, probably doesn't belong with the parser part of the framework. // But since it's definitely something we want, I'm keeping this here for reference until it finds it's final home. // Hugi 2024-10-19 - return new NGElementNotFoundElement( tag.declaration().type() ); + return new NGElementNotFoundElement( type ); } } - private static Map associationsFromDeclaration( final NGDeclaration declaration ) { + private static Map associationsFromDeclaration( final Map bindings, final boolean isInline ) { final Map associations = new HashMap<>(); - for( Entry entry : declaration.bindings().entrySet() ) { - associations.put( entry.getKey(), NGAssociationFactory.toAssociation( entry.getValue(), declaration.isInline() ) ); + for( Entry entry : bindings.entrySet() ) { + associations.put( entry.getKey(), NGAssociationFactory.toAssociation( entry.getValue(), isInline ) ); } return associations; diff --git a/ng-appserver/src/main/java/ng/appserver/templating/PBasicNode.java b/ng-appserver/src/main/java/ng/appserver/templating/PBasicNode.java index 76d34fff..d876de96 100644 --- a/ng-appserver/src/main/java/ng/appserver/templating/PBasicNode.java +++ b/ng-appserver/src/main/java/ng/appserver/templating/PBasicNode.java @@ -1,10 +1,30 @@ package ng.appserver.templating; +import java.util.List; +import java.util.Map; import java.util.Objects; +import ng.appserver.templating.NGDeclaration.NGBindingValue; + public record PBasicNode( NGDynamicHTMLTag tag ) implements PNode { public PBasicNode { Objects.requireNonNull( tag ); } + + public boolean isInline() { + return tag().declaration().isInline(); + } + + public String type() { + return tag().declaration().type(); + } + + public Map bindings() { + return tag().declaration().bindings(); + } + + public List children() { + return tag().childrenWithStringsProcessedAndCombined(); + } } \ No newline at end of file