...
| Code Block |
|---|
import groovy.xml.MarkupBuilder
// standard book
def standardBook1(builder) { builder.book(title:'Groovy in Action', author:'Dierk König et al') }
// other standard books
def standardBook2(builder, audience) { builder.book(title:"Groovy for ${audience}") }
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.truck(id:'ABC123') {
box(country:'Australia') {
box(country:'Australia', state:'QLD') {
standardBook1(this)
standardBook1(this)
standardBook2(this, 'VBA Macro writers')
}
box(country:'Australia', state:'NSW') {
box(country:'Australia', state:'NSW', city:'Sydney') {
standardBook1(this)
standardBook2(this, 'COBOL Programmers')
}
box(country:'Australia', state:'NSW', suburb:'Albury') {
standardBook1(this)
standardBook2(this, 'Fortran Programmers')
}
}
}
box(country:'USA') {
box(country:'USA', state:'CA') {
standardBook1(this)
standardBook2(this, 'Ruby Programmers')
}
}
box(country:'Germany') {
box(country:'Germany', city:'Berlin') {
standardBook1(this)
standardBook2(this, 'PHP Programmers')
}
}
box(country:'UK') {
box(country:'UK', city:'London') {
standardBook1(this)
standardBook2(this, 'Haskel Programmers')
}
}
}
println writer.toString()
|
Next, let's refactored refactor out a few more methods to end up with the following:
...