Class Groovy


  • public abstract class Groovy
    extends java.lang.Object
    Static methods for specialized Groovy integration.
    • 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 to Groovy.Ratpack
      • chain

        public static Handler chain​(ServerConfig serverConfig,
                                    @DelegatesTo(value=GroovyChain.class,strategy=1)
                                    Closure<?> closure)
                             throws java.lang.Exception
        Builds a handler chain, with no backing registry.
        Parameters:
        serverConfig - The application server config
        closure - The chain definition
        Returns:
        A handler
        Throws:
        java.lang.Exception - any exception thrown by the given closure
      • chain

        public static Handler chain​(Registry registry,
                                    @DelegatesTo(value=GroovyChain.class,strategy=1)
                                    Closure<?> closure)
                             throws java.lang.Exception
        Builds a chain, backed by the given registry.
        Parameters:
        registry - The registry.
        closure - The chain building closure.
        Returns:
        A handler
        Throws:
        java.lang.Exception - any exception thrown by the given closure
      • groovyTemplate

        public static TextTemplate groovyTemplate​(java.lang.String id)
        Creates a renderable 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​(java.lang.String id)
        Creates a renderable 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​(java.lang.String id,
                                                  java.lang.String type)
        Creates a renderable Groovy based template, using no model.
        Parameters:
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.lang.String id,
                                                          java.lang.String type)
        Creates a renderable Groovy based markup template, using no model.
        Parameters:
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • groovyTemplate

        public static TextTemplate groovyTemplate​(java.util.Map<java.lang.String,​?> model,
                                                  java.lang.String id)
        Creates a renderable Groovy based template, using the default content type.
        Parameters:
        model - The template model
        id - The id/name of the template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.util.Map<java.lang.String,​?> model,
                                                          java.lang.String id)
        Creates a renderable Groovy based markup template, using the default content type.
        Parameters:
        model - The template model
        id - The id/name of the template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.lang.String id,
                                                          Action<? super com.google.common.collect.ImmutableMap.Builder<java.lang.String,​java.lang.Object>> modelBuilder)
        Creates a renderable Groovy based markup template, using the default content type.
        Parameters:
        id - the id/name of the template
        modelBuilder - an action the builds a model map
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.lang.String id,
                                                          java.lang.String type,
                                                          Action<? super com.google.common.collect.ImmutableMap.Builder<java.lang.String,​java.lang.Object>> modelBuilder)
        Creates a renderable Groovy based markup template.
        Parameters:
        id - the id/name of the template
        type - The content type of template
        modelBuilder - an action the builds a model map
        Returns:
        a template
      • groovyTemplate

        public static TextTemplate groovyTemplate​(java.util.Map<java.lang.String,​?> model,
                                                  java.lang.String id,
                                                  java.lang.String type)
        Creates a renderable Groovy based template.
        Parameters:
        model - The template model
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • groovyMarkupTemplate

        public static MarkupTemplate groovyMarkupTemplate​(java.util.Map<java.lang.String,​?> model,
                                                          java.lang.String id,
                                                          java.lang.String type)
        Creates a renderable Groovy based template.
        Parameters:
        model - The template model
        id - The id/name of the template
        type - The content type of template
        Returns:
        a template
      • chain

        public static void chain​(Chain chain,
                                 @DelegatesTo(value=GroovyChain.class,strategy=1)
                                 Closure<?> closure)
                          throws java.lang.Exception
        Immediately executes the given closure against the given chain, as a GroovyChain.
        Parameters:
        chain - the chain to add handlers to
        closure - the definition of handlers to add
        Throws:
        java.lang.Exception - any exception thrown by closure
      • chain

        public static Action<Chain> chain​(@DelegatesTo(value=GroovyChain.class,strategy=1)
                                          Closure<?> closure)
                                   throws java.lang.Exception
        Creates a chain action implementation from the given closure.
        Parameters:
        closure - the definition of handlers to add
        Returns:
        The created action
        Throws:
        java.lang.Exception - any exception thrown by closure
      • markupBuilder

        public static Markup markupBuilder​(java.lang.CharSequence contentType,
                                           java.lang.CharSequence encoding,
                                           @DelegatesTo(value=groovy.xml.MarkupBuilder.class,strategy=1)
                                           Closure<?> closure)
        Renderable object for markup built using Groovy's MarkupBuilder.
         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 markup
        encoding - The character encoding of the markup
        closure - The definition of the markup
        Returns:
        A renderable object (i.e. to be used with the Context.render(Object) method
      • byContent

        public static Handler byContent​(Registry registry,
                                        @DelegatesTo(value=GroovyByMethodSpec.class,strategy=1)
                                        Closure<?> closure)
                                 throws java.lang.Exception
        Builds a content negotiating handler.
        Parameters:
        registry - the registry to obtain handlers from for by-class lookups
        closure - the spec action
        Returns:
        a content negotiating handler
        Throws:
        java.lang.Exception - any thrown by action
        Since:
        1.5
      • byMethod

        public static Handler byMethod​(Registry registry,
                                       @DelegatesTo(value=GroovyByContentSpec.class,strategy=1)
                                       Closure<?> closure)
                                throws java.lang.Exception
        Builds a multi method handler.
        Parameters:
        registry - the registry to obtain handlers from for by-class lookups
        closure - the spec action
        Returns:
        a multi method handler
        Throws:
        java.lang.Exception - any thrown by action
        Since:
        1.5