Created
February 21, 2012 10:17
-
-
Save lyhcode/1875635 to your computer and use it in GitHub Desktop.
Groovy output HTML with MarkupBuilder
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
| import groovy.xml.MarkupBuilder | |
| def sb = new StringWriter() | |
| def html = new MarkupBuilder(sb) | |
| html.doubleQuotes = true | |
| html.expandEmptyElements = true | |
| html.omitEmptyAttributes = false | |
| html.omitNullAttributes = false | |
| html.html { | |
| head { | |
| title ('Heading') | |
| script (src: 'test.js', type: 'text/javascript') | |
| } | |
| body { | |
| mkp.yieldUnescaped('<!--') | |
| mkp.yield('<test>') | |
| mkp.yieldUnescaped('-->') | |
| ul { | |
| for (def i=0;i<10;i++) { | |
| li (i) | |
| } | |
| } | |
| } | |
| } | |
| println sb.toString() | |
| |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment