Skip to content

Commit

Permalink
Hide internals of PBasicNode from outside world
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Nov 17, 2024
1 parent c7f1861 commit 5fba637
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, NGAssociation> 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<String, NGAssociation> associationsFromDeclaration( final NGDeclaration declaration ) {
private static Map<String, NGAssociation> associationsFromDeclaration( final Map<String, NGBindingValue> bindings, final boolean isInline ) {
final Map<String, NGAssociation> associations = new HashMap<>();

for( Entry<String, NGBindingValue> entry : declaration.bindings().entrySet() ) {
associations.put( entry.getKey(), NGAssociationFactory.toAssociation( entry.getValue(), declaration.isInline() ) );
for( Entry<String, NGBindingValue> entry : bindings.entrySet() ) {
associations.put( entry.getKey(), NGAssociationFactory.toAssociation( entry.getValue(), isInline ) );
}

return associations;
Expand Down
20 changes: 20 additions & 0 deletions ng-appserver/src/main/java/ng/appserver/templating/PBasicNode.java
Original file line number Diff line number Diff line change
@@ -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<String, NGBindingValue> bindings() {
return tag().declaration().bindings();
}

public List<PNode> children() {
return tag().childrenWithStringsProcessedAndCombined();
}
}

0 comments on commit 5fba637

Please sign in to comment.