Regen Plugin
Dependency :
compile ":regen:0.3.2"
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.groovyregen.templates = 'regen.packed.listEdit' regen.excludeDomainClasses = ['RequestMap', 'CommonFilter','RejectedRecord', 'AppProperty', 'FileDetails']
regen all all
Generate Artefacts
The regen command syntax supports wildcard * and the key word all. The generic syntax isgrails 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 |
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
- src/groovy/templates/scaffolding/regen/packed/listEdit
static regenTemplates = 'regen.packed.listEdit'regen.templates = 'regen.packed.listEdit'
regen.includeDomainClasses = ['Employee','Group','Location','Task']
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
- 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 undergrails-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:- a name ending with _Generator_.
- a closure named alter.
- inText: the text of the file
- genTask: the GenerationTask in progress
- 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).