Skip to content

Commit

Permalink
Fix s2ui-override
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Sep 27, 2017
1 parent f878d9e commit bea47bf
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
classes
cobertura.ser
kindlegen
/plugin/src/main/templates/views
46 changes: 45 additions & 1 deletion plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,48 @@ apply from: "${rootProject.projectDir}/gradle/artifactoryPublish.gradle"

assets {
packagePlugin = true
}
}


task copyGspIntoTemplates {
ext.inputFolders = ['aclClass',
'aclEntry',
'aclObjectIdentity',
'aclSid',
'includes',
'layouts',
'login',
'persistentLogin',
'register',
'registrationCode',
'requestmap',
'role',
'securityInfo',
'user']
doLast {
mkdir "${project.projectDir}/src/main/templates/views"
for ( String folder : inputFolders ) {
mkdir "${project.projectDir}/src/main/templates/views/${folder}"
}
for ( int i = 0; i < inputFolders.size(); i++ ) {
copy {
from(fileTree("${project.projectDir}/grails-app/views/${inputFolders[i]}")) {
include '*.gsp'
}
into "${project.projectDir}/src/main/templates/views/${inputFolders[i]}"
}
}
}
}

task removeGspFromTemplates {
doLast {
for ( String folder : copyGspIntoTemplates.inputFolders ) {
delete "${project.projectDir}/src/main/templates/views/${folder}"
}
delete "${project.projectDir}/src/main/templates/views"
}

}

compileAstJava.dependsOn copyGspIntoTemplates
112 changes: 87 additions & 25 deletions plugin/src/main/scripts/s2ui-override.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,26 @@ File viewsDir = new File(grailsApp, 'views')
File layoutsDir = new File(viewsDir, 'layouts')

def controllers = [aclclass: 'AclClass',
aclentry: 'AclEntry',
aclobjectidentity: 'AclObjectIdentity',
aclsid: 'AclSid',
persistentlogin: 'PersistentLogin',
register: 'Register',
registrationcode: 'RegistrationCode',
requestmap: 'Requestmap',
role: 'Role',
securityinfo: 'SecurityInfo',
user: 'User']
aclentry: 'AclEntry',
aclobjectidentity: 'AclObjectIdentity',
aclsid: 'AclSid',
persistentlogin: 'PersistentLogin',
register: 'Register',
registrationcode: 'RegistrationCode',
requestmap: 'Requestmap',
role: 'Role',
securityinfo: 'SecurityInfo',
user: 'User']

if (!controllerPackage) {
if ('layout' == type) {
// special case for springSecurityUI.gsp
copy 'layouts/springSecurityUI.gsp', layoutsDir

copy 'includes/_ajaxLogin.gsp', new File(viewsDir, 'includes')
copy template('views/layouts/springSecurityUI.gsp'), file('grails-app/views/layouts/')
copy template('views/includes/_ajaxLogin.gsp'), new File(viewsDir, 'includes')
return
}

if ('auth' == type) {
// special case for auth.gsp
copy 'login/auth.gsp', new File(viewsDir, 'login')
copy template('views/login/auth.gsp'), new File(viewsDir, 'login')
return
}
}
Expand Down Expand Up @@ -93,21 +90,86 @@ File destinationDirectory = new File(controllersDir, directoryName)
destinationDirectory.mkdirs()

render template(controller + 'Controller.groovy.template'),
new File(destinationDirectory, controller + 'Controller.groovy'),
[packageDeclaration: "package $controllerPackage"], false
new File(destinationDirectory, controller + 'Controller.groovy'),
[packageDeclaration: "package $controllerPackage"], false

// copy the GSPs
directoryName = GrailsNameUtils.getPropertyName(controller)
File gspDirectory = new File(viewsDir, directoryName)

for (resource in resources(directoryName + '/*.gsp')) {
copy resource, gspDirectory
}

switch ( directoryName ) {
case 'aclClass':
copy template('views/aclClass/create.gsp'), new File(viewsDir, 'aclClass')
copy template('views/aclClass/edit.gsp'), new File(viewsDir, 'aclClass')
copy template('views/aclClass/search.gsp'), new File(viewsDir, 'aclClass')
break
case 'aclEntry':
copy template('views/aclEntry/create.gsp'), new File(viewsDir, 'aclEntry')
copy template('views/aclEntry/edit.gsp'), new File(viewsDir, 'aclEntry')
copy template('views/aclEntry/search.gsp'), new File(viewsDir, 'aclEntry')
break
case 'aclObjectIdentity':
copy template('views/aclObjectIdentity/create.gsp'), new File(viewsDir, 'aclObjectIdentity')
copy template('views/aclObjectIdentity/edit.gsp'), new File(viewsDir, 'aclObjectIdentity')
copy template('views/aclObjectIdentity/search.gsp'), new File(viewsDir, 'aclObjectIdentity')
break
case 'aclSid':
copy template('views/aclSid/create.gsp'), new File(viewsDir, 'aclSid')
copy template('views/aclSid/edit.gsp'), new File(viewsDir, 'aclSid')
copy template('views/aclSid/search.gsp'), new File(viewsDir, 'aclSid')
break
case 'persistentLogin':
copy template('views/persistentLogin/search.gsp'), new File(viewsDir, 'persistentLogin')
copy template('views/persistentLogin/edit.gsp'), new File(viewsDir, 'persistentLogin')
break
case 'register':
copy template('views/register/forgotPassword.gsp'), new File(viewsDir, 'register')
copy template('views/register/register.gsp'), new File(viewsDir, 'register')
copy template('views/register/resetPassword.gsp'), new File(viewsDir, 'register')
break
case 'registrationCode':
copy template('views/registrationCode/search.gsp'), new File(viewsDir, 'registrationCode')
copy template('views/registrationCode/edit.gsp'), new File(viewsDir, 'registrationCode')
break
case 'requestmap':
copy template('views/requestmap/create.gsp'), new File(viewsDir, 'requestmap')
copy template('views/requestmap/edit.gsp'), new File(viewsDir, 'requestmap')
copy template('views/requestmap/search.gsp'), new File(viewsDir, 'requestmap')
break
case 'role':
copy template('views/role/create.gsp'), new File(viewsDir, 'role')
copy template('views/role/edit.gsp'), new File(viewsDir, 'role')
copy template('views/role/search.gsp'), new File(viewsDir, 'role')
break
case 'securityInfo':
copy template('views/securityInfo/config.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/currentAuth.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/filterChains.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/logoutHandlers.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/mappings.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/providers.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/secureChannel.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/usercache.gsp'), new File(viewsDir, 'securityInfo')
copy template('views/securityInfo/voters.gsp'), new File(viewsDir, 'securityInfo')
break
case 'user':
copy template('views/user/create.gsp'), new File(viewsDir, 'user')
copy template('views/user/edit.gsp'), new File(viewsDir, 'user')
copy template('views/user/search.gsp'), new File(viewsDir, 'user')
break
}

if ('register' == type) {
layoutsDir.mkdirs()
render template('register.gsp.template'),
new File(layoutsDir, 'register.gsp'),
[:],
false
}
copy template('views/layouts/register.gsp'), file('grails-app/views/layouts/')
}

private void copy(pathOrResource, File destinationDirectory) {
if ( !destinationDirectory.exists() ) {
destinationDirectory.mkdirs()
}

copy resource(pathOrResource), destinationDirectory
}

0 comments on commit bea47bf

Please sign in to comment.