2020import x .junk .NGElementNotFoundElement ;
2121
2222/**
23- * Serves as a bridge between the "new and old world" for template parsing
23+ * Bridges the "new and old world" for template parsing
2424 */
2525
2626public class NGTemplateParserProxy {
2727
2828 private final String _htmlString ;
2929 private final String _wodString ;
3030
31+ /**
32+ * @param htmlString The HTML to parse
33+ * @param wodString The associated wod/declarations
34+ */
3135 public NGTemplateParserProxy ( String htmlString , String wodString ) {
3236 Objects .requireNonNull ( htmlString );
3337 Objects .requireNonNull ( wodString );
@@ -36,29 +40,30 @@ public NGTemplateParserProxy( String htmlString, String wodString ) {
3640 _wodString = wodString ;
3741 }
3842
43+ /**
44+ * @return A parsed element template
45+ */
3946 public NGElement parse () throws NGDeclarationFormatException , NGHTMLFormatException {
40- final PNode pNode = new NGTemplateParser ( _htmlString , _wodString ).parse ();
41- return toDynamicElement ( pNode );
47+ final PNode rootNode = new NGTemplateParser ( _htmlString , _wodString ).parse ();
48+ return toDynamicElement ( rootNode );
4249 }
4350
4451 private static NGElement toDynamicElement ( final PNode node ) {
4552 return switch ( node ) {
4653 case PBasicNode n -> toDynamicElement ( n .tag () );
47- case PGroupNode n -> childrenToTemplate ( n .children () );
54+ case PGroupNode n -> toTemplate ( n .children () );
4855 case PHTMLNode n -> new NGHTMLBareString ( n .value () );
4956 case PCommentNode n -> new NGHTMLCommentString ( n .value () );
5057 };
5158 }
5259
5360 private static NGElement toDynamicElement ( final NGDynamicHTMLTag tag ) {
5461 try {
55- return NGApplication .dynamicElementWithName ( tag .declaration ().type (), associationsFromDeclaration ( tag .declaration () ), childrenToTemplate ( tag .childrenWithStringsProcessedAndCombined () ), Collections .emptyList () );
62+ return NGApplication .dynamicElementWithName ( tag .declaration ().type (), associationsFromDeclaration ( tag .declaration () ), toTemplate ( tag .childrenWithStringsProcessedAndCombined () ), Collections .emptyList () );
5663 }
5764 catch ( NGElementNotFoundException e ) {
58- // FIXME:
59- // Very experimental functionality at the moment and definitely does not belong with the parser part of the framework.
60- // But since it's definitely something we want to add ad some point, I'm keeping it for reference
61- // Hugi 2024-10-19
65+ // FIXME: Experimental functionality, probably doesn't belong with the parser part of the framework.
66+ // 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
6267 return new NGElementNotFoundElement ( tag .declaration ().type () );
6368 }
6469 }
@@ -74,25 +79,25 @@ private static Map<String, NGAssociation> associationsFromDeclaration( final NGD
7479 }
7580
7681 /**
77- * @return The tag's template
82+ * @return An element/ template from the given list of nodes.
7883 */
79- private static NGElement childrenToTemplate ( final List <PNode > children ) {
84+ private static NGElement toTemplate ( final List <PNode > nodes ) {
8085
81- // FIXME: Children should never really be null. I'm still hesitant to replace it with an empty list though, since in my mind that represents an empty container tag. Food for thought... // Hugi 2024-11-15
82- if ( children == null ) {
86+ // FIXME: Shouldn't really ever be null. Still hesitant to replace it with an empty list though, since in my mind that represents an empty container tag. Food for thought... // Hugi 2024-11-15
87+ if ( nodes == null ) {
8388 return null ;
8489 }
8590
86- final List <NGElement > childElements = new ArrayList <>();
91+ final List <NGElement > elements = new ArrayList <>();
8792
88- for ( final PNode pNode : children ) {
89- childElements .add ( toDynamicElement ( pNode ) );
93+ for ( final PNode pNode : nodes ) {
94+ elements .add ( toDynamicElement ( pNode ) );
9095 }
9196
92- if ( childElements .size () == 1 ) {
93- return childElements .getFirst ();
97+ if ( elements .size () == 1 ) {
98+ return elements .getFirst ();
9499 }
95100
96- return NGDynamicGroup .of ( childElements );
101+ return NGDynamicGroup .of ( elements );
97102 }
98103}
0 commit comments