public abstract class Groovy extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
Groovy.Ratpack
The definition of a Groovy Ratpack application.
|
static class |
Groovy.Script
Methods for working with Groovy scripts as application components.
|
Modifier and Type | Method and Description |
---|---|
static Handler |
byContent(Registry registry,
Closure<?> closure)
Builds a content negotiating handler.
|
static Handler |
byMethod(Registry registry,
Closure<?> closure)
Builds a multi method handler.
|
static void |
chain(Chain chain,
Closure<?> closure)
|
static Action<Chain> |
chain(Closure<?> closure)
Creates a chain action implementation from the given closure.
|
static Handler |
chain(Registry registry,
Closure<?> closure)
Builds a chain, backed by the given registry.
|
static Handler |
chain(ServerConfig serverConfig,
Closure<?> closure)
Builds a handler chain, with no backing registry.
|
static Handler |
chain(ServerConfig serverConfig,
Registry registry,
Closure<?> closure)
Builds a chain, backed by the given registry.
|
static Action<Chain> |
chainAction(Closure<?> closure)
Creates a chain action based on the given closure.
|
static Handler |
groovyHandler(Closure<?> closure)
Creates a handler instance from a closure.
|
static MarkupTemplate |
groovyMarkupTemplate(Map<String,?> model,
String id)
Creates a
renderable Groovy based markup template, using the default content type. |
static MarkupTemplate |
groovyMarkupTemplate(Map<String,?> model,
String id,
String type)
Creates a
renderable Groovy based template. |
static MarkupTemplate |
groovyMarkupTemplate(String id)
Creates a
renderable Groovy based markup template, using no model and the default content type. |
static MarkupTemplate |
groovyMarkupTemplate(String id,
Action<? super ImmutableMap.Builder<String,Object>> modelBuilder)
Creates a
renderable Groovy based markup template, using the default content type. |
static MarkupTemplate |
groovyMarkupTemplate(String id,
String type)
Creates a
renderable Groovy based markup template, using no model. |
static MarkupTemplate |
groovyMarkupTemplate(String id,
String type,
Action<? super ImmutableMap.Builder<String,Object>> modelBuilder)
Creates a
renderable Groovy based markup template. |
static TextTemplate |
groovyTemplate(Map<String,?> model,
String id)
Creates a
renderable Groovy based template, using the default content type. |
static TextTemplate |
groovyTemplate(Map<String,?> model,
String id,
String type)
Creates a
renderable Groovy based template. |
static TextTemplate |
groovyTemplate(String id)
Creates a
renderable Groovy based template, using no model and the default content type. |
static TextTemplate |
groovyTemplate(String id,
String type)
Creates a
renderable Groovy based template, using no model. |
static Markup |
htmlBuilder(Closure<?> closure)
Shorthand for
markupBuilder(CharSequence, Charset, Closure) with a content type of "text/html" and "UTF-8" encoding. |
static Markup |
markupBuilder(CharSequence contentType,
CharSequence encoding,
Closure<?> closure)
Renderable object for markup built using Groovy's
MarkupBuilder . |
static Markup |
markupBuilder(CharSequence contentType,
Charset encoding,
Closure<?> closure) |
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 { bindings { // example of registering a module add(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(ServerConfig serverConfig, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
serverConfig
- The application server configclosure
- The chain definitionException
- any exception thrown by the given closurepublic static Handler chain(@Nullable ServerConfig serverConfig, @Nullable Registry registry, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
serverConfig
- The application server configregistry
- The registry.closure
- The chain building closure.Exception
- any exception thrown by the given closurepublic static Handler chain(Registry registry, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
registry
- The registry.closure
- The chain building closure.Exception
- any exception thrown by the given closurepublic static Action<Chain> chainAction(@DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure)
closure
- The chain building closure.public static TextTemplate groovyTemplate(String id)
renderable
Groovy based template, using no model and the default content type.id
- The id/name of the templatepublic static MarkupTemplate groovyMarkupTemplate(String id)
renderable
Groovy based markup template, using no model and the default content type.id
- The id/name of the templatepublic static TextTemplate 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 MarkupTemplate groovyMarkupTemplate(String id, String type)
renderable
Groovy based markup template, using no model.id
- The id/name of the templatetype
- The content type of templatepublic static TextTemplate 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 MarkupTemplate groovyMarkupTemplate(Map<String,?> model, String id)
renderable
Groovy based markup template, using the default content type.model
- The template modelid
- The id/name of the templatepublic static MarkupTemplate groovyMarkupTemplate(String id, Action<? super ImmutableMap.Builder<String,Object>> modelBuilder)
renderable
Groovy based markup template, using the default content type.id
- the id/name of the templatemodelBuilder
- an action the builds a model mappublic static MarkupTemplate groovyMarkupTemplate(String id, String type, Action<? super ImmutableMap.Builder<String,Object>> modelBuilder)
renderable
Groovy based markup template.id
- the id/name of the templatetype
- The content type of templatemodelBuilder
- an action the builds a model mappublic static TextTemplate 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 MarkupTemplate groovyMarkupTemplate(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
chain
- the chain to add handlers toclosure
- the definition of handlers to addException
- any exception thrown by closure
public static Action<Chain> chain(@DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
closure
- 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(CharSequence, Charset, Closure)
with a content type of "text/html"
and "UTF-8"
encoding.closure
- The html definitionContext.render(Object)
methodpublic static Markup markupBuilder(CharSequence contentType, CharSequence 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)
methodpublic static Markup markupBuilder(CharSequence contentType, Charset encoding, @DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1) Closure<?> closure)
public static Handler byContent(Registry registry, @DelegatesTo(value=GroovyByMethodSpec.class,strategy=1) Closure<?> closure) throws Exception
registry
- the registry to obtain handlers from for by-class lookupsclosure
- the spec actionException
- any thrown by action
public static Handler byMethod(Registry registry, @DelegatesTo(value=GroovyByContentSpec.class,strategy=1) Closure<?> closure) throws Exception
registry
- the registry to obtain handlers from for by-class lookupsclosure
- the spec actionException
- any thrown by action