Skip to content

Commit ece1e88

Browse files
author
Adam Collins
committed
#474 #478 #480 rollback a bug fix that removed necessary functionality
1 parent eceb6d4 commit ece1e88

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,34 @@ The dependent services point to other production servers by default
123123
##### Fork [spatial-hub](https://github.com/AtlasOfLivingAustralia/spatial-hub), modify and deploy
124124
* Use when development of spatial-hub is expected. It can be used with with the other methods.
125125
126+
##### Local files
127+
* Adding files local to deployment can add new layouts and resources.
128+
129+
1. Add a new layout gsp to the ```/data/spatial-hub/views/layouts``` directory.
130+
```
131+
/data/spatial-hub/views/layouts/myLayout.gsp
132+
```
133+
134+
1. Additional assets can be added to the ```/data/spatial-hub/assets``` directory.
135+
```
136+
/data/spatial-hub/assets/css/externalCss.css
137+
/data/spatial-hub/assets/js/externalJs.js
138+
/data/spatial-hub/assets/img/externalImage.png
139+
```
140+
141+
1. Assets can be referenced within the new layout gsp.
142+
```
143+
<asset:stylesheet src="css/externalCss.css" />
144+
<asset:javascript src="js/externalJs.js" />
145+
<asset:image src="img/externalImg.png" />
146+
```
147+
148+
1. Change config to use the new layout gsp.
149+
```
150+
# edit /data/spatial-hub/config/spatial-hub-config.properties
151+
skin.layout=myLayout
152+
```
153+
126154
> **Note:**
127155
>
128156
> A forked [commonui-bs3](https://github.com/AtlasOfLivingAustralia/commonui-bs3) can be deployed to ```/data/spatial-hub/assets/``` and used with the config

build.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ buildscript {
77
dependencies {
88
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
99
classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.7"
10-
classpath("com.bertramlabs.plugins:asset-pipeline-gradle:3.4.6")
10+
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:3.4.6"
11+
// classpath 'com.bertramlabs.plugins:asset-pipeline-core:3.2.4'
1112
}
1213
}
1314

@@ -93,6 +94,8 @@ dependencies {
9394
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
9495
implementation group: 'commons-lang', name: 'commons-lang', version: '2.6'
9596

97+
implementation group: "com.bertramlabs.plugins", name: "asset-pipeline-gradle", version: "3.4.6"
98+
9699
//Angular profile wrapper needs
97100
assets 'com.craigburke.angular:angular-annotate-asset-pipeline:2.4.1'
98101
//Fork version in Atlas

grails-app/init/au/org/ala/spatial/portal/BootStrap.groovy

+69
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package au.org.ala.spatial.portal
22

3+
import asset.pipeline.AssetPipelineConfigHolder
4+
import asset.pipeline.fs.FileSystemAssetResolver
35
import au.org.ala.cas.util.AuthenticationUtils
46
import au.org.ala.web.AuthService
57
import grails.converters.JSON
8+
import org.apache.commons.io.FileUtils
69
import org.apache.commons.lang3.StringUtils
710
import org.springframework.core.io.FileSystemResource
811
import org.springframework.core.io.Resource
@@ -28,9 +31,75 @@ class BootStrap {
2831
// fix config data types when using a .properties file
2932
parseConfig()
3033

34+
// support for external layouts
35+
//
36+
// e.g. config "skin.layout=myLayout" will use the layout file /data/spatial-hub/views/layouts/myLayout.gsp
37+
//
38+
// support external files with the asset tag in the layout gsp
39+
// e.g.
40+
// files
41+
// /data/spatial-hub/assets/css/externalCss.css
42+
// /data/spatial-hub/assets/js/externalJs.js
43+
// /data/spatial-hub/assets/img/externalImage.png
44+
// asset tags
45+
// <asset:stylesheet src="css/externalCss.css" />
46+
// <asset:javascript src="js/externalJs.js" />
47+
// <asset:image src="img/externalImg.png" />
48+
//
49+
// Support the use of the default "skin.layout=generic" with a local "headerAndFooter.baseURL" by the creating files
50+
// /data/spatial-hub/assets/css/bootstrap.min.css
51+
// /data/spatial-hub/assets/css/ala-styles.css
52+
addExternalViews()
53+
addExternalAssets(servletContext)
54+
3155
portalService.updateListQueries()
3256
}
3357

58+
def addExternalViews = {
59+
groovyPageLocator.addResourceLoader(new ResourceLoader() {
60+
61+
@Override
62+
Resource getResource(String s) {
63+
File resource = new File('/data/spatial-hub/views' + s)
64+
if (resource.exists()) {
65+
return new FileSystemResource(resource)
66+
}
67+
return null
68+
}
69+
70+
@Override
71+
ClassLoader getClassLoader() {
72+
return null
73+
}
74+
})
75+
}
76+
77+
def addExternalAssets = { servletContext ->
78+
try {
79+
File src = new File('/data/spatial-hub/assets')
80+
81+
if (src.exists() && src.isDirectory()) {
82+
// asset-pipeline resolves files differently depending on the presence of a manifest
83+
if (AssetPipelineConfigHolder.manifest) {
84+
// copy external asset files into expanded war assets directory so they can be discovered
85+
File dst = new File(servletContext.getRealPath("/assets"))
86+
87+
if (dst.exists() && dst.isDirectory()) {
88+
FileUtils.copyDirectory(src, dst)
89+
} else {
90+
log.error("External assets are unavailable. Expanded WAR asset directory '${dst.path}' does not exist.")
91+
}
92+
} else {
93+
// a new Resolver is required to find the external assets at runtime
94+
def resolver = new FileSystemAssetResolver("external-assets", '/data/spatial-hub/assets', false)
95+
AssetPipelineConfigHolder.registerResolver(resolver)
96+
}
97+
}
98+
} catch (err) {
99+
log.error("External assets are not available.", err)
100+
}
101+
}
102+
34103
def destroy = {
35104
}
36105

0 commit comments

Comments
 (0)