Skip to content

Commit

Permalink
Moved actual element construction from NGDynamicHTMLTag to the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
hugithordarson committed Oct 17, 2024
1 parent 16fcb8c commit afa6448
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package ng.appserver.templating;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import ng.appserver.NGApplication;
import ng.appserver.NGComponentReference;
import ng.appserver.NGElement;
import ng.appserver.elements.NGDynamicGroup;
Expand Down Expand Up @@ -125,14 +122,4 @@ public void addChildElement( final Object stringOrElement ) {

_children.add( stringOrElement );
}

public NGElement dynamicElement( final Map<String, NGDeclaration> declarations ) throws NGDeclarationFormatException {
final NGDeclaration declaration = declarations.get( declarationName() );

if( declaration == null ) {
throw new NGDeclarationFormatException( "No declaration for dynamic element (or component) named '%s'".formatted( declarationName() ) );
}

return NGApplication.dynamicElementWithName( declaration.type(), declaration.associations(), template(), Collections.emptyList() );
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ng.appserver.templating;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.StringTokenizer;

import ng.appserver.NGApplication;
import ng.appserver.NGAssociation;
import ng.appserver.NGAssociationFactory;
import ng.appserver.NGElement;
Expand Down Expand Up @@ -109,7 +111,7 @@ public void didParseClosingWebObjectTag( final String parsedString ) throws NGDe
throw new NGHTMLFormatException( message );
}

final NGElement element = _currentDynamicTag.dynamicElement( _declarations );
final NGElement element = dynamicElement( _currentDynamicTag, _declarations );
_currentDynamicTag = parentDynamicTag;
_currentDynamicTag.addChildElement( element );
}
Expand Down Expand Up @@ -158,6 +160,16 @@ static String extractDeclarationName( final String tagPart ) throws NGHTMLFormat
throw new NGHTMLFormatException( "Can't initialize dynamic tag '%s', no 'name' attribute found".formatted( tagPart ) );
}

private static NGElement dynamicElement( NGDynamicHTMLTag tag, final Map<String, NGDeclaration> declarations ) throws NGDeclarationFormatException {
final NGDeclaration declaration = declarations.get( tag.declarationName() );

if( declaration == null ) {
throw new NGDeclarationFormatException( "No declaration for dynamic element (or component) named '%s'".formatted( tag.declarationName() ) );
}

return NGApplication.dynamicElementWithName( declaration.type(), declaration.associations(), tag.template(), Collections.emptyList() );
}

private static NGDeclaration parseInlineTag( final String tag, final int colonIndex, final int nextInlineBindingNumber ) throws NGHTMLFormatException {

final StringBuilder keyBuffer = new StringBuilder();
Expand Down

0 comments on commit afa6448

Please sign in to comment.