Regen Plugin

  • Tags : /
  • Latest : 0.3.2
  • Last Updated: 11 April 2012
  • Grails version : 1.3.5 > *
  • Authors : null
1 vote
Dependency :
compile ":regen:0.3.2"

Documentation Source

Summary

Regen provides a generation framework. The regen process is a set of pluggable artefacts under grails-app/generators.

Regen comes with a default list of generators. Using those default, you can merge your custom code with the templates specified in your domain class.

The generator currently provided work better with the templates included in the plugin packed.

Installation

grails install-plugin regen

Description

Change your code and pages and still regenerate ! Program to the template !

Overview

Regen gives you full control over the generation process including:

  • Generate many artefact in one command.
  • Manage the list of fields for each view.
  • Change the generated code AND change the domain class and regenerate again.
  • Change any step of the process, from reading templates to saving final result.
  • Add new steps.
  • Create new conventions in the COC Grails spirit.

User Guide

Quick guide

put those lines in Config.groovy

regen.templates = 'regen.packed.listEdit'
regen.excludeDomainClasses = ['RequestMap', 'CommonFilter','RejectedRecord', 'AppProperty', 'FileDetails']

From the command line type

regen all all

You may have to restart

Generate Artefacts

The regen command syntax supports wildcard * and the key word all. The generic syntax is

grails regen artefact-name domain-class-name

Examples
Generate controller for domain class javamug.Address
>grails regen controller javamug.Address
If there is only one Address domain class, this will do
>grails regen controller Address
Generate view create for domain class javamug.Address
>grails regen view-create Address
>grails regen create Address
Generate all views for domain class javamug.Address
>grails regen views Address
Generate all gsp starting with list for domain class javamug.Address
>grails regen list* Address
Generate all controllers for all domain classes under package javamug
>grails regen controller javamug.*
Generate all artefacts for domain class Address
>grails regen * Address
>grails regen all Address
Generate all artefact for all domain classes
>grails regen * *
>grails regen all all

You will love the wild card when you change a template in the middle of a project.

Manage Fields

The list of fields displayed in each view is managed from the domain class. Quotes are optional. Here is an example:

String streetAddress
  String city
  String county
  String state
  String country
  String postalCode
  double latitude
  double longitude

static views = { list = [streetAddress, city, county, state, country, postalCode] _list = list _listRow = list _listRowButtons = list show = list + [latitude, longitude, dateCreated, lastUpdated ] create = show - [latitude, longitude] edit = create }

Templates

Regen enable template driven applications.

What can I generate?

Any artefact, service, groovy, java or text file can be generated. Currently they are default generators for domain, controller, and view.

How do I select the template?

You can use many sets of templates. Templates are stored under

  • src/groovy/templates/scaffolding/regen
Currently, I created an example of templates under
  • src/groovy/templates/scaffolding/regen/packed/listEdit
To use those templates for a domain class, add this line to the domainClass
static regenTemplates = 'regen.packed.listEdit'

To enable those templates globally for all domain classes, add this to Config.groovy

regen.templates = 'regen.packed.listEdit'

To define the list of domainClasses included in the wild card '*' (or 'all') list them in Config.grooy

regen.includeDomainClasses = ['Employee','Group','Location','Task']

If there are too many domain classes, and you just want to exclude some of them, use:

regen.excludeDomainClasses = ['RequestMap', 'CommonFilter','RejectedRecord', 'AppProperty', 'FileDetails']

Example of templates

Here is a proposed best practice. Jack also have images, and css that work together. the images are stored under

  • web-app/images/regen/packed/listEdit
the css under
  • web-app/css/regen/packed/listEdit

Change the generation process (advanced)

How do I support of new artefact

In order to support a new type of file, just create at least one generator under grails-apps/generators . The name of the file must end with Generator . For example, suppose that you want to generate custom xml handler files. You create generators ending with the name XmlhandlerGenerator such as fooXmlhandlerGenerator@. Note that the Type @Xmlhandler must be capitalized and lowercase (A-z (+)a-z0-9-_ (+)).

Then you invoke
>regen xmlhandler *
OR
>regen xmlhandler package.*
OR
>regen * com.todaddy.Baby

How do I create a generator

A generators is a pojo with the following conventions:

  1. a name ending with _Generator_.
  2. a closure named alter.
alter take a Map argument filled with the following:
  • inText: the text of the file
  • genTask: the GenerationTask in progress
genTask provide the following attributes:
  • domainClass: the domainClass relevant for this artefact if any
  • targetTypeName: The artefact type. For example: 'domain', 'controller', 'view'
  • targetName: The specific name of the generated file. Currently only used for views. For example: 'show', 'list', 'edit'
  • genSteps: The ordered set of steps to be run for this task.
  • properties: A scratch pad. (tb replaced by an Expando).
The alter closure return the modified text. This may not be the final text, but just an intermediary transformation. Often the inText returned unmodifed; the generator just add some information into the properties of the genTask for further generator steps to use.