Chapter 10
[ 257 ]
indent.times {print " "}
println "createNode(${name}, ${value})"
indent++
return name
}
def createNode(name, Map attributes){
indent.times {print " "}
println "createNode(${name}, ${attributes})"
indent++
return name
}
def createNode(name, Map attributes, value){
indent.times {print " "}
println "createNode(${name}, ${attributes}, ${value})"
indent++
return name
}
void setParent(parent, child){
indent.times {print " "}
println "setParent(${parent}, ${child})"
}
void nodeCompleted(parent, node) {
indent--
indent.times {print " "}
println "nodeCompleted(${parent}, ${node})"
}
}
To use this builder, all that we need to do is to construct one and start writing some
markup with it. Here we have some markup for building customer records, but
as this builder does not care what the method tags are, we could write whatever
markup we please:
given:
def builder = new LogBuilder()
def customers = builder.customers {
customer{
id(1001)
name(firstName:"Fred",surname:"Flintstone")
address("billing", street:"1 Rock Road",city:"Bedrock")
address("shipping", street:"1 Rock Road",city:"Bedrock")
}
}
expect: