feature request: builder append(...) or insert(...) #2

Closed
wstidolph opened this Issue Aug 3, 2011 · 1 comment

2 participants

@wstidolph

I'd like to be able to append nodes to the TropoBuilder, or to insert an existing TropoBuilder's nodes into a new Builder; I would have expected this somewhere directly in BuilderSupport, but I don't see it so I'll ask you if it's easy for the TropoBuilder ;) or if maybe I just missed it ...

Here's a use case I need to handle:

(in a grails controller)

TropoBuilder tb = new TropoBuilder();
someLogic(tb)
tb.append {
    on(event:'continue',next:'tropo/commonEndpoint')
}

def someLogic(TroboBuilder tb){
    tb.tropo{
        say('hello')
    }
}

Another approach would be to support something like:

TropoBuilder tb1 = new TopoBuilder()
 tb1.tropo { say('goodbye') }

TropoBuilder tb2 = new TopoBuilder()
 tb2.tropo {
    say('hello')
    insert(tb1)
    on(event:'continue',next:'')
}    

(I find the second approach a bit more flexible)

I ran into this need specifically while building Tropo commands in state machine actions using the http://grails.org/plugin/fsm FSM plugin, because it uses the 'on' keyword. So, when I use an action block in the FSM to generate a tropo builder and when put 'on' into blocks inside the action definition of the state machine, they vanish from the tropo output! But, it's a more general issue of wanting to assemble complex tropo commands one chunk at a time.

@mpermar mpermar added a commit that closed this issue Aug 4, 2011
@mpermar mpermar Added new append method to TropoBuilder which allows to create more
complex builders by appending existing builder objects.

This closes #2
07bb766
@mpermar mpermar closed this in 07bb766 Aug 4, 2011
@mpermar
Tropo member

Hi Wayne,

I think you already could do what you wanted if you don't use the closure format. Like for example here in the tests:

https://github.com/tropo/tropo-webapi-grails/blob/master/test/unit/com/tropo/grails/TropoBuilderTests.groovy#L500

But anyways, I added support for explicitly embedding other builders, so now you can add an append(builder) element within another builder.

You can find an example here:

https://github.com/tropo/tropo-webapi-grails/blob/master/test/unit/com/tropo/grails/TropoBuilderTests.groovy#L707

This is available in version 0.1.2 of the plugin, or you can pick the changes from the source tree.

Best,
Martin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment