Skip to content

Commit 5fba637

Browse files
Hide internals of PBasicNode from outside world
1 parent c7f1861 commit 5fba637

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

ng-appserver/src/main/java/ng/appserver/templating/NGTemplateParserProxy.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,34 @@ public NGElement parse() throws NGDeclarationFormatException, NGHTMLFormatExcept
5050

5151
private static NGElement toDynamicElement( final PNode node ) {
5252
return switch( node ) {
53-
case PBasicNode n -> toDynamicElement( n.tag() );
53+
case PBasicNode n -> toDynamicElement( n );
5454
case PGroupNode n -> toTemplate( n.children() );
5555
case PHTMLNode n -> new NGHTMLBareString( n.value() );
5656
case PCommentNode n -> new NGHTMLCommentString( n.value() );
5757
};
5858
}
5959

60-
private static NGElement toDynamicElement( final NGDynamicHTMLTag tag ) {
60+
private static NGElement toDynamicElement( final PBasicNode node ) {
61+
62+
final String type = node.type();
63+
final Map<String, NGAssociation> associations = associationsFromDeclaration( node.bindings(), node.isInline() );
64+
final NGElement childTemplate = toTemplate( node.children() );
65+
6166
try {
62-
return NGApplication.dynamicElementWithName( tag.declaration().type(), associationsFromDeclaration( tag.declaration() ), toTemplate( tag.childrenWithStringsProcessedAndCombined() ), Collections.emptyList() );
67+
return NGApplication.dynamicElementWithName( type, associations, childTemplate, Collections.emptyList() );
6368
}
6469
catch( NGElementNotFoundException e ) {
6570
// FIXME: Experimental functionality, probably doesn't belong with the parser part of the framework.
6671
// 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
67-
return new NGElementNotFoundElement( tag.declaration().type() );
72+
return new NGElementNotFoundElement( type );
6873
}
6974
}
7075

71-
private static Map<String, NGAssociation> associationsFromDeclaration( final NGDeclaration declaration ) {
76+
private static Map<String, NGAssociation> associationsFromDeclaration( final Map<String, NGBindingValue> bindings, final boolean isInline ) {
7277
final Map<String, NGAssociation> associations = new HashMap<>();
7378

74-
for( Entry<String, NGBindingValue> entry : declaration.bindings().entrySet() ) {
75-
associations.put( entry.getKey(), NGAssociationFactory.toAssociation( entry.getValue(), declaration.isInline() ) );
79+
for( Entry<String, NGBindingValue> entry : bindings.entrySet() ) {
80+
associations.put( entry.getKey(), NGAssociationFactory.toAssociation( entry.getValue(), isInline ) );
7681
}
7782

7883
return associations;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,30 @@
11
package ng.appserver.templating;
22

3+
import java.util.List;
4+
import java.util.Map;
35
import java.util.Objects;
46

7+
import ng.appserver.templating.NGDeclaration.NGBindingValue;
8+
59
public record PBasicNode( NGDynamicHTMLTag tag ) implements PNode {
610

711
public PBasicNode {
812
Objects.requireNonNull( tag );
913
}
14+
15+
public boolean isInline() {
16+
return tag().declaration().isInline();
17+
}
18+
19+
public String type() {
20+
return tag().declaration().type();
21+
}
22+
23+
public Map<String, NGBindingValue> bindings() {
24+
return tag().declaration().bindings();
25+
}
26+
27+
public List<PNode> children() {
28+
return tag().childrenWithStringsProcessedAndCombined();
29+
}
1030
}

0 commit comments

Comments
 (0)