root/AjaxFlow/trunk/scripts/CreateAjaxFlow.groovy @ 56

Revision 56, 4.4 KB (checked in by work@…, 3 years ago)

- updated plugin to 0.1.2
- added clickable tab support
- upgraded to grails 1.3.5 as gscf issue with 1.3.5 was resolved
- improved controller
- improved templates

Line 
1/*
2 *  AjaxFlow, a plugin for Ajaxified Webflows
3 *  Copyright (C) 2010 Jeroen Wesbeek
4 *
5 *  Licensed under the Apache License, Version 2.0 (the "License");
6 *  you may not use this file except in compliance with the License.
7 *  You may obtain a copy of the License at
8 *
9 *  http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17import groovy.text.SimpleTemplateEngine
18
19includeTargets << grailsScript("_GrailsArgParsing")
20
21USAGE = """
22    create-ajax-flow PKG NAME
23
24where
25    PKG  = The package name to use for your controller.
26    NAME = The name of your controller and the name of the folder for your views and images
27
28"""
29
30def parseArgs() {
31        args = args ? args.split('\n') : []
32    switch (args.size()) {
33            case 2:
34                        println "Using package ${args[0]} to create the Ajax Flow Controller"
35                    println "and using the following name for the Controller name, and the"
36                                        println "view and images folders: ${args[1]}"
37                    return [args[0], args[1]]
38                    break
39            default:
40                        usage()
41                        break
42    }
43}
44
45private void usage() {
46        println "Usage:\n${USAGE}"
47        System.exit(1)
48}
49
50target(default: 'Sets up a new ajax base flow, ready for customization') {
51        // define variables
52        def packageName, name, packageDir, nameDir
53
54        // get arguments
55        (packageName, name) = parseArgs()
56
57        // change package name into directory
58    packageDir  = packageName.replace('[.|/|\\]', '/')
59        nameDir         = name.toLowerCase().replace(' ', '-')
60
61        // define date stamp (YYYYMMDD)
62        def today = String.format('%tY%<tm%<td', new GregorianCalendar() )
63
64        // set up the template engine
65        def engine = new SimpleTemplateEngine()
66
67        // define bindings
68        def controllerName = name[0].toUpperCase() + name.substring(1) + "Controller"
69        def binding     = [
70                'packageName'   : packageName,
71                'className'             : controllerName,
72                'viewDir'               : nameDir,
73                'name'                  : name,
74                'nameError'             : name + 'Error',
75                'css'                   : name + '.css',
76                'today'                 : today,
77                'openTag'               : '<%',
78                'closeTag'              : '%>'
79        ]
80
81        // create the ajax flow controller
82        mkdir(dir:"${basedir}/grails-app/controllers/${packageDir}")
83        def controllerTemplate  = engine.createTemplate(new FileReader("${ajaxFlowPluginDir}/src/templates/controllers/WizardController.groovy")).make(binding)
84        new File("${basedir}/grails-app/controllers/${packageDir}/${controllerName}.groovy").write(controllerTemplate.toString())
85
86        // create the ajax flow javascript
87        mkdir(dir:"${basedir}/web-app/css")
88        def jsTemplate  = engine.createTemplate(new FileReader("${ajaxFlowPluginDir}/src/templates/css/wizard.css")).make(binding)
89        new File("${basedir}/web-app/css/${name}.css").write(jsTemplate.toString())
90
91        // set up the ajax flow views
92        def views       = [
93                // index view
94            'index.gsp',
95
96                // common views
97                'common/_ajaxflow.gsp',
98                'common/_navigation.gsp',
99                'common/_page_header.gsp',
100                'common/_page_footer.gsp',
101                'common/_tabs.gsp',
102                'common/_on_page.gsp',
103                'common/_refresh_flow.gsp',
104
105                // page views
106                'pages/_page_one.gsp',
107                'pages/_page_two.gsp',
108                'pages/_page_three.gsp',
109                'pages/_page_four.gsp',
110                'pages/_final_page.gsp',
111                'pages/_error.gsp'
112        ]
113        def viewTemplate = ''
114        mkdir(dir:"${basedir}/grails-app/views/${nameDir}")
115        mkdir(dir:"${basedir}/grails-app/views/${nameDir}/common")
116        mkdir(dir:"${basedir}/grails-app/views/${nameDir}/pages")
117        views.each {
118                // parse view template
119                viewTemplate = engine.createTemplate(new FileReader("${ajaxFlowPluginDir}/src/templates/views/${it}")).make(binding)
120
121                // write file
122                new File("${basedir}/grails-app/views/${nameDir}/${it}").write(viewTemplate.toString())
123        }
124
125        // set up images
126        mkdir(dir:"${basedir}/web-app/images/${nameDir}")
127        copy(file:"${ajaxFlowPluginDir}/src/templates/images/arrowL.gif", tofile: "${basedir}/web-app/images/${nameDir}/arrowL.gif", overwrite: false)
128        copy(file:"${ajaxFlowPluginDir}/src/templates/images/arrowR.gif", tofile: "${basedir}/web-app/images/${nameDir}/arrowR.gif", overwrite: false)
129        copy(file:"${ajaxFlowPluginDir}/src/templates/images/spacer.gif", tofile: "${basedir}/web-app/images/${nameDir}/spacer.gif", overwrite: false)
130
131        println ""
132        println "Your Ajax Flow is set up, please browse to /${name} to view your new Ajax Flow"
133}
Note: See TracBrowser for help on using the browser.