Skip to content

Commit a1368b5

Browse files
author
Antony Jones
committed
Clearer instruction on removal and inclusion of resources with overrides, including some simple examples.
1 parent 976b85b commit a1368b5

File tree

1 file changed

+60
-1
lines changed

1 file changed

+60
-1
lines changed

src/docs/guide/5. Overriding resources.gdoc

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,65 @@ modules = {
2121

2222
All you do is re-define the module inside your "overrides" clause (yes this mean no module can be called "overrides"), and provide new values for defaultBundle, dependsOn and individual resource attributes.
2323

24+
Arguments passed to the resource call in "overrides" are merged into those for the original resource, before being processed. Therefore you can change or clear any values previously declared.
25+
26+
{note}
2427
To override the attributes of resources, the original resource needs to have an id declared on it, or you can use the URI of the original resource if no id was provided.
28+
{note}
29+
30+
{warning}
31+
There are a few caveats whilst using overrides, namely:
32+
33+
* To remove an existing resource, override it and point to an empty file.
34+
* You can't add a new resource to a bundle which didn't exist in the original module, you can only replace existing ones, but
35+
* If you want to add a completely new resource, create a new module and dependOn it in your overrides.
36+
{warning}
37+
38+
For example, if you wanted to override an external library in the test environment:
39+
40+
MyResources.groovy
41+
{code:java}
42+
modules = {
43+
rockpool {
44+
dependsOn 'core'
45+
resource id: 'rockpool-js', url: '/js/rockpool.js', bundle: 'rockpoolBundle'
46+
}
47+
}
48+
{code}
49+
50+
Then you could override it in another resources file to remove it (probably using environment support to make it specific to the test environment):
51+
52+
MyOverrideResources.groovy
53+
{code:java}
54+
modules = {
55+
overrides {
56+
rockpool {
57+
dependsOn 'core'
58+
resource id: 'rockpool-js', url: '/js/blank.js'
59+
}
60+
}
61+
}
62+
{code}
63+
64+
{note}
65+
Note we don't need to include the bundle attribute, it is inherited from MyResources.groovy.
66+
{note}
67+
68+
Perhaps you want to add a completely new file to the above bundle which never existed in the old module. It's a bit more tricky:
69+
70+
MyOverrideResources.groovy
71+
{code:java}
72+
modules = {
73+
overrides {
74+
rockpool {
75+
dependsOn 'core', 'mockpool'
76+
resource id: 'rockpool-js', url: '/js/blank.js'
77+
}
78+
}
79+
mockpool {
80+
resource url: '/js/mockpool.js'
81+
}
82+
}
83+
{code}
2584

26-
Arguments passed to the resource call in "overrides" are merged into those for the original resource, before being processed. Therefor you can change or clear any values previously declared.
85+
Here, we depend on the new 'mockpool' module to include the brand new resource.

0 commit comments

Comments
 (0)