Skip to content

Commit

Permalink
Use Thymeleaf's Assignation.left/right values, fixes #244
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Jan 31, 2025
1 parent 4f333be commit 8e84b97
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2016, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -23,7 +23,7 @@ import org.thymeleaf.standard.expression.Assignation
* attributes. This is really a wrapper around Thymeleaf's {@link Assignation}
* class, but simplified to just the left and right hand components in string
* form.
*
*
* @author Emanuel Rabina
*/
class VariableDeclaration {
Expand All @@ -33,18 +33,19 @@ class VariableDeclaration {

/**
* Constructor, create an instance from a Thymeleaf assignation.
*
*
* @param assignation
*/
VariableDeclaration(Assignation assignation) {

(name, value) = assignation.stringRepresentation.split('=')
name = assignation.left.toString()
value = assignation.right.toString()
}

/**
* Reconstructs the variable for use with {@code th:with}.
*
* @return {name}=${value}
*
* @return {@code name=value}
*/
@Override
String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
/*
* Copyright 2016, Emanuel Rabina (http://www.ultraq.net.nz/)
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,7 +26,7 @@ import groovy.transform.TupleConstructor
* found withing {@code th:with} processors. This is really a wrapper around
* Thymeleaf's {@link AssignationUtils} class, which is a crazy house of code
* that splits the expression string into the parts needed by this dialect.
*
*
* @author Emanuel Rabina
*/
@TupleConstructor(defaults = false)
Expand All @@ -37,15 +37,16 @@ class VariableDeclarationParser {
/**
* Parse a variable declaration string, returning as many variable declaration
* objects as there are variable declarations.
*
*
* @param declarationString
* @return List of variable declaration objects.
*/
List<VariableDeclaration> parse(String declarationString) {

def assignationSequence = AssignationUtils.parseAssignationSequence(context, declarationString, false)
return assignationSequence?.collect { assignation ->
return new VariableDeclaration(assignation)
if (assignationSequence) {
return assignationSequence.collect { assignation -> new VariableDeclaration(assignation) }
}
return []
}
}

0 comments on commit 8e84b97

Please sign in to comment.