Package ratpack.groovy
Class Groovy
- java.lang.Object
-
- ratpack.groovy.Groovy
-
public abstract class Groovy extends Object
Static methods for specialized Groovy integration.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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 Action<Chain>
chain(Closure<?> closure)
Creates a chain action implementation from the given closure.static void
chain(Chain chain, Closure<?> closure)
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 Handler
chain(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(String id)
Creates arenderable
Groovy based markup template, using no model and the default content type.static MarkupTemplate
groovyMarkupTemplate(String id, String type)
Creates arenderable
Groovy based markup template, using no model.static MarkupTemplate
groovyMarkupTemplate(String id, String type, Action<? super com.google.common.collect.ImmutableMap.Builder<String,Object>> modelBuilder)
Creates arenderable
Groovy based markup template.static MarkupTemplate
groovyMarkupTemplate(String id, Action<? super com.google.common.collect.ImmutableMap.Builder<String,Object>> modelBuilder)
Creates arenderable
Groovy based markup template, using the default content type.static MarkupTemplate
groovyMarkupTemplate(Map<String,?> model, String id)
Creates arenderable
Groovy based markup template, using the default content type.static MarkupTemplate
groovyMarkupTemplate(Map<String,?> model, String id, String type)
Creates arenderable
Groovy based template.static TextTemplate
groovyTemplate(String id)
Creates arenderable
Groovy based template, using no model and the default content type.static TextTemplate
groovyTemplate(String id, String type)
Creates arenderable
Groovy based template, using no model.static TextTemplate
groovyTemplate(Map<String,?> model, String id)
Creates arenderable
Groovy based template, using the default content type.static TextTemplate
groovyTemplate(Map<String,?> model, String id, String type)
Creates arenderable
Groovy based template.static Markup
htmlBuilder(Closure<?> closure)
Shorthand formarkupBuilder(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'sMarkupBuilder
.static Markup
markupBuilder(CharSequence contentType, Charset encoding, Closure<?> closure)
static void
ratpack(Closure<?> closure)
Starts a Ratpack app, defined by the given closure.
-
-
-
Method Detail
-
ratpack
public static void ratpack(@DelegatesTo(value=Ratpack.class,strategy=1) Closure<?> closure)
Starts a Ratpack app, defined by the given closure.This method is used in Ratpack scripts as the entry point.
import ratpack.groovy.sql.SqlModule import static ratpack.groovy.Groovy.* ratpack { bindings { // example of registering a module add(new SqlModule()) } handlers { // define the application handlers get("foo") { render "bar" } } }
Standalone Scripts
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.Full Applications
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.- Parameters:
closure
- The definition closure, delegating toGroovy.Ratpack
-
chain
public static Handler chain(ServerConfig serverConfig, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
Builds a handler chain, with no backing registry.- Parameters:
serverConfig
- The application server configclosure
- The chain definition- Returns:
- A handler
- Throws:
Exception
- any exception thrown by the given closure
-
chain
public static Handler chain(@Nullable ServerConfig serverConfig, @Nullable Registry registry, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
Builds a chain, backed by the given registry.- Parameters:
serverConfig
- The application server configregistry
- The registry.closure
- The chain building closure.- Returns:
- A handler
- Throws:
Exception
- any exception thrown by the given closure
-
chain
public static Handler chain(Registry registry, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
Builds a chain, backed by the given registry.- Parameters:
registry
- The registry.closure
- The chain building closure.- Returns:
- A handler
- Throws:
Exception
- any exception thrown by the given closure
-
chainAction
public static Action<Chain> chainAction(@DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure)
Creates a chain action based on the given closure.- Parameters:
closure
- The chain building closure.- Returns:
- A chain action
-
groovyTemplate
public static TextTemplate groovyTemplate(String id)
Creates arenderable
Groovy based template, using no model and the default content type.- Parameters:
id
- The id/name of the template- Returns:
- a template
-
groovyMarkupTemplate
public static MarkupTemplate groovyMarkupTemplate(String id)
Creates arenderable
Groovy based markup template, using no model and the default content type.- Parameters:
id
- The id/name of the template- Returns:
- a template
-
groovyTemplate
public static TextTemplate groovyTemplate(String id, String type)
Creates arenderable
Groovy based template, using no model.- Parameters:
id
- The id/name of the templatetype
- The content type of template- Returns:
- a template
-
groovyMarkupTemplate
public static MarkupTemplate groovyMarkupTemplate(String id, String type)
Creates arenderable
Groovy based markup template, using no model.- Parameters:
id
- The id/name of the templatetype
- The content type of template- Returns:
- a template
-
groovyTemplate
public static TextTemplate groovyTemplate(Map<String,?> model, String id)
Creates arenderable
Groovy based template, using the default content type.- Parameters:
model
- The template modelid
- The id/name of the template- Returns:
- a template
-
groovyMarkupTemplate
public static MarkupTemplate groovyMarkupTemplate(Map<String,?> model, String id)
Creates arenderable
Groovy based markup template, using the default content type.- Parameters:
model
- The template modelid
- The id/name of the template- Returns:
- a template
-
groovyMarkupTemplate
public static MarkupTemplate groovyMarkupTemplate(String id, Action<? super com.google.common.collect.ImmutableMap.Builder<String,Object>> modelBuilder)
Creates arenderable
Groovy based markup template, using the default content type.- Parameters:
id
- the id/name of the templatemodelBuilder
- an action the builds a model map- Returns:
- a template
-
groovyMarkupTemplate
public static MarkupTemplate groovyMarkupTemplate(String id, String type, Action<? super com.google.common.collect.ImmutableMap.Builder<String,Object>> modelBuilder)
Creates arenderable
Groovy based markup template.- Parameters:
id
- the id/name of the templatetype
- The content type of templatemodelBuilder
- an action the builds a model map- Returns:
- a template
-
groovyTemplate
public static TextTemplate groovyTemplate(Map<String,?> model, String id, String type)
Creates arenderable
Groovy based template.- Parameters:
model
- The template modelid
- The id/name of the templatetype
- The content type of template- Returns:
- a template
-
groovyMarkupTemplate
public static MarkupTemplate groovyMarkupTemplate(Map<String,?> model, String id, String type)
Creates arenderable
Groovy based template.- Parameters:
model
- The template modelid
- The id/name of the templatetype
- The content type of template- Returns:
- a template
-
groovyHandler
public static Handler groovyHandler(@DelegatesTo(value=GroovyContext.class,strategy=1) Closure<?> closure)
Creates a handler instance from a closure.- Parameters:
closure
- The closure to convert to a handler- Returns:
- The created handler
-
chain
public static void chain(Chain chain, @DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
- Parameters:
chain
- the chain to add handlers toclosure
- the definition of handlers to add- Throws:
Exception
- any exception thrown byclosure
-
chain
public static Action<Chain> chain(@DelegatesTo(value=GroovyChain.class,strategy=1) Closure<?> closure) throws Exception
Creates a chain action implementation from the given closure.- Parameters:
closure
- the definition of handlers to add- Returns:
- The created action
- Throws:
Exception
- any exception thrown byclosure
-
htmlBuilder
public static Markup htmlBuilder(@DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1) Closure<?> closure)
Shorthand formarkupBuilder(CharSequence, Charset, Closure)
with a content type of"text/html"
and"UTF-8"
encoding.- Parameters:
closure
- The html definition- Returns:
- A renderable object (i.e. to be used with the
Context.render(Object)
method
-
markupBuilder
public static Markup markupBuilder(CharSequence contentType, CharSequence encoding, @DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1) Closure<?> closure)
Renderable object for markup built using Groovy'sMarkupBuilder
.import static ratpack.groovy.Groovy.markupBuilder get("some/path") { render markupBuilder("text/html", "UTF-8") { // MarkupBuilder DSL in here } }
- Parameters:
contentType
- The content type of the markupencoding
- The character encoding of the markupclosure
- The definition of the markup- Returns:
- A renderable object (i.e. to be used with the
Context.render(Object)
method
-
markupBuilder
public static Markup markupBuilder(CharSequence contentType, Charset encoding, @DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1) Closure<?> closure)
-
byContent
public static Handler byContent(Registry registry, @DelegatesTo(value=GroovyByMethodSpec.class,strategy=1) Closure<?> closure) throws Exception
Builds a content negotiating handler.- Parameters:
registry
- the registry to obtain handlers from for by-class lookupsclosure
- the spec action- Returns:
- a content negotiating handler
- Throws:
Exception
- any thrown byaction
- Since:
- 1.5
-
byMethod
public static Handler byMethod(Registry registry, @DelegatesTo(value=GroovyByContentSpec.class,strategy=1) Closure<?> closure) throws Exception
Builds a multi method handler.- Parameters:
registry
- the registry to obtain handlers from for by-class lookupsclosure
- the spec action- Returns:
- a multi method handler
- Throws:
Exception
- any thrown byaction
- Since:
- 1.5
-
-