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 void |
chain(Chain chain,
Closure<?> closure)
Immediately executes the given
closure against the given chain, as a {@link GroovyChain}. |
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)
Creates a specialized Groovy context.
|
static Handler |
groovyHandler(Closure<?> closure)
Creates a handler instance from a closure.
|
static Template |
groovyTemplate(Map<String,?> model,
String id)
Creates a
renderable Groovy based template, using the default content type. |
static Template |
groovyTemplate(Map<String,?> model,
String id,
String type)
Creates a
renderable Groovy based template. |
static Template |
groovyTemplate(String id)
Creates a
renderable Groovy based template, using no model and the default content type. |
static Template |
groovyTemplate(String id,
String type)
Creates a
renderable Groovy based template, using no model. |
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
- any exception thrown by the given closurepublic static GroovyContext context(Context context)
context
- The context to convert to a Groovy contextpublic static Handler chain(@Nullable 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
- any exception thrown by the given closurepublic static Template groovyTemplate(String id)
renderable
Groovy based template, using no model and the default content type.id
- The id/name of the templatepublic static Template groovyTemplate(String id, String type)
renderable
Groovy based template, using no model.id
- The id/name of the templatetype
- The content type of templatepublic static Template groovyTemplate(Map<String,?> model, String id)
renderable
Groovy based template, using the default content type.model
- The template modelid
- The id/name of the templatepublic static Template groovyTemplate(Map<String,?> model, String id, String type)
renderable
Groovy based template.model
- The template modelid
- The id/name of the templatetype
- The content type of templatepublic static Handler groovyHandler(@DelegatesTo(value=GroovyContext.class,strategy=1) Closure<?> closure)
closure
- The closure to convert to a handlerpublic static void chain(Chain chain, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
closure
against the given chain, as a {@link GroovyChain}.chain
- the chain to add handlers toclosure
- the definition of handlers to addException
- any exception thrown by 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"
encoding.closure
- 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