I am missing something obvious I know but...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

I am missing something obvious I know but...

Russel Winder
I am trying to generate menus for webpages.  I have a groovy list with
the specification in and there can be submenus.  My first experiments at
trying to do this all worked fine but now I want to do things
sensibly :-)

I came up with:

         import groovy.xml.StreamingMarkupBuilder
       
        def generateMenu ( menu , current ) {
          ( new StreamingMarkupBuilder ( ) ).bind {
            def generateMenuEntries = { items , level ->
              items.each { entry ->
                  li ( id : ( entry[1] == current ) ? 'current' :
        'other' , class : 'level' + level ) {
                    a ( href : entry[1] , rel : 'self' , entry[0] +
        ( ( entry[2] != null ) ? ' >>' : '' ) )
                  }
                  if ( ( entry[1] == current ) && ( entry[2] != null ) )
        { generateMenuEntries ( entry[2] , level + 1 ) }
              }
            }
            ul { generateMenuEntries ( menu , 0 ) }
          }
        }
       
        println generateMenu ( evaluate ( ( new File
        ( 'Template/menu' ) ).text ) , 'index.html' )

but StreamingMarkupBuilder does not recognize that generateMenuEntries
is a closure.  Is it the case that StreamingMarkupBuilder only looks for
functions and not closures when processing the markup?

--
Russel.
====================================================
Dr Russel Winder                +44 20 7585 2200
41 Buckmaster Road              +44 7770 465 077
London SW11 1EN, UK             [hidden email]

signature.asc (198 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: I am missing something obvious I know but...

Russel Winder
On Thu, 2006-07-27 at 11:05 +0100, Russel Winder wrote:

Doh, it turns out I had failed to evaluate the string in the new file.
The downside of dynamic typing.

Sorry for cluttering up people's email.

The decoding of the error message from StreamingMarkupBuilder is still
an issue though.  I have no idea how to cure it though, indeed whether
it is curable.

--
Russel.
====================================================
Dr Russel Winder                +44 20 7585 2200
41 Buckmaster Road              +44 7770 465 077
London SW11 1EN, UK             [hidden email]

signature.asc (198 bytes) Download Attachment