public abstract class Groovy extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Groovy.Ratpack
The definition of a Groovy Ratpack application.
|
Modifier and Type | Method and Description |
---|---|
static Handler |
chain(LaunchConfig launchConfig,
Closure<?> closure)
Builds a handler chain, with no backing registry.
|
static Handler |
chain(LaunchConfig launchConfig,
Registry registry,
Closure<?> closure)
Builds a chain, backed by the given registry.
|
static GroovyContext |
context(Context context) |
static Handler |
groovyHandler(Closure<?> closure) |
static Template |
groovyTemplate(Map<String,?> model,
String id) |
static Template |
groovyTemplate(Map<String,?> model,
String id,
String type) |
static Template |
groovyTemplate(String id) |
static Template |
groovyTemplate(String id,
String type) |
static Markup |
htmlBuilder(Closure<?> closure)
Shorthand for
markupBuilder(String, String, groovy.lang.Closure) with a content type of "text/html" and "UTF-8" encoding |
static Markup |
markupBuilder(String contentType,
String encoding,
Closure<?> closure)
Renderable object for markup built using Groovy's
MarkupBuilder . |
static void |
ratpack(Closure<?> closure)
Starts a Ratpack app, defined by the given closure.
|
public static void ratpack(@DelegatesTo(value=Groovy.Ratpack.class,strategy=1) Closure<?> closure)
This method is used in Ratpack scripts as the entry point.
import ratpack.session.SessionModule import static ratpack.groovy.Groovy.* ratpack { modules { // example of registering a module register(new SessionModule()) } handlers { // define the application handlers get("foo") { render "bar" } } }
This method can be used by standalone scripts to start a Ratpack application.
That is, you could save the above content in a file named “ratpack.groovy
” (the name is irrelevant),
then start the application by running `groovy ratpack.groovy
` on the command line.
It's also possible to build Groovy Ratpack applications with a traditional class based entry point.
The GroovyRatpackMain
class provides such an entry point.
In such a mode, a script like above is still used to define the application, but the script is no longer the entry point.
Ratpack will manage the compilation and execution of the script internally.
closure
- The definition closure, delegating to Groovy.Ratpack
public static Handler chain(LaunchConfig launchConfig, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
launchConfig
- The application launch configclosure
- The chain definitionException
public static GroovyContext context(Context context)
public static Handler chain(LaunchConfig launchConfig, @Nullable Registry registry, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
launchConfig
- The application launch configregistry
- The registry.closure
- The chain building closure.Exception
public static Handler groovyHandler(@DelegatesTo(value=GroovyContext.class,strategy=1) Closure<?> closure)
public static Markup htmlBuilder(@DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1) Closure<?> closure)
markupBuilder(String, String, groovy.lang.Closure)
with a content type of "text/html"
and "UTF-8"
encodingclosure
- The html definitionContext.render(Object)
methodpublic static Markup markupBuilder(String contentType, String encoding, @DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1) Closure<?> closure)
MarkupBuilder
.
import static ratpack.groovy.Groovy.markupBuilder get("some/path") { render markupBuilder("text/html", "UTF-8") { // MarkupBuilder DSL in here } }
contentType
- The content type of the markupencoding
- The character encoding of the markupclosure
- The definition of the markupContext.render(Object)
method