Last active
September 15, 2020 05:15
-
-
Save kdabir/1885146 to your computer and use it in GitHub Desktop.
Using MarkupBuilder to generate html markup in groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MarkupBuilder is a lot cleaner way of generating valid xml/html markup | |
// than writing tags as string and forgetting to close one ;) | |
def writer = new StringWriter() // html is written here by markup builder | |
def markup = new groovy.xml.MarkupBuilder(writer) // the builder | |
markup.html{ | |
table { | |
tr { | |
td(class:"row", "hello world!") | |
} | |
} | |
} | |
println writer.toString() | |
/* produces output : | |
<html> | |
<table> | |
<tr> | |
<td>hello world!</td> | |
</tr> | |
</table> | |
</html> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment