hoping to use groovy to write a groovy.text.Template for Asciidoctor markup. So far :

//-----------------------------------

public class AsciidocTemplate implements groovy.text.Template
{
boolean includeHeaderFooter = true;

Asciidoctor asciidoctor = create();
org.asciidoctor.Options asciidoctorJOptions=["backend": "html","header_footer":includeHeaderFooter]

def payload="";
Map binding = [:]

public AsciidocTemplate()
{
} // end of constructor

public AsciidocTemplate(def payload)
{
    this.payload = payload;
} // end of constructor

// use doctor to transform the template
public Writable process()
{
    def output = asciidoctor.render(this.payload, asciidoctorJOptions);
    Writer ou = output;
    return ou;        
} // end of make

Writable make()
{
    return process();  //output as Writable;
} // end of make

// -----------------------------------

The render() returns a string, how do we convert that string into an object that implements the Writable interface, i just dont get it. Also can't see how to use/read/store the returned 'Writable' object either :-P

有帮助吗?

解决方案

You can use the asWritable method on a Closure to get a Writable returned, ie:

Writable process()
{
    def output = asciidoctor.render(this.payload, asciidoctorJOptions);
    { w -> w.println output }.asWritable()
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top