mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
DOCS: [GitBook] Code block caption (#1999)
Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
committed by
GitHub
parent
0051b41720
commit
45ad35e68a
@ -19,17 +19,18 @@ the currently-loading file (which may not be the file where the
|
||||
is interpreted relative to the program's working directory at the time
|
||||
of the call.
|
||||
|
||||
{% code title="dnsconfig.js" %}
|
||||
```javascript
|
||||
// dnsconfig.js
|
||||
require('kubernetes/clusters.js');
|
||||
|
||||
D("mydomain.net", REG, PROVIDER,
|
||||
IncludeKubernetes()
|
||||
);
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
{% code title="kubernetes/clusters.js" %}
|
||||
```javascript
|
||||
// kubernetes/clusters.js
|
||||
require('./clusters/prod.js');
|
||||
require('./clusters/dev.js');
|
||||
|
||||
@ -37,29 +38,32 @@ function IncludeKubernetes() {
|
||||
return [includeK8Sprod(), includeK8Sdev()];
|
||||
}
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
{% code title="kubernetes/clusters/prod.js" %}
|
||||
```javascript
|
||||
// kubernetes/clusters/prod.js
|
||||
function includeK8Sprod() {
|
||||
return [
|
||||
// ...
|
||||
];
|
||||
}
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
{% code title="kubernetes/clusters/dev.js" %}
|
||||
```javascript
|
||||
// kubernetes/clusters/dev.js
|
||||
function includeK8Sdev() {
|
||||
return [
|
||||
// ...
|
||||
];
|
||||
}
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
You can also use it to require JSON files and initialize variables with it:
|
||||
|
||||
{% code title="dnsconfig.js" %}
|
||||
```javascript
|
||||
// dnsconfig.js
|
||||
var domains = require('./domain-ip-map.json')
|
||||
|
||||
for (var domain in domains) {
|
||||
@ -68,14 +72,16 @@ for (var domain in domains) {
|
||||
);
|
||||
}
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
{% code title="domain-ip-map.json" %}
|
||||
```javascript
|
||||
// domain-ip-map.json
|
||||
{
|
||||
"mydomain.net": "1.1.1.1",
|
||||
"myotherdomain.org": "5.5.5.5"
|
||||
}
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
# Future
|
||||
|
||||
|
@ -30,17 +30,17 @@ require_glob("./domains/", false);
|
||||
One more important thing to note: `require_glob()` is as smart as `require()` is. It loads files always relative to the JavaScript
|
||||
file where it's being executed in. Let's go with an example, as it describes it better:
|
||||
|
||||
`dnscontrol.js`:
|
||||
|
||||
{% code title="dnsconfig.js" %}
|
||||
```javascript
|
||||
require("domains/index.js");
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
`domains/index.js`:
|
||||
|
||||
{% code title="domains/index.js" %}
|
||||
```javascript
|
||||
require_glob("./user1/");
|
||||
```
|
||||
{% endcode %}
|
||||
|
||||
This will now load files being present underneath `./domains/user1/` and **NOT** at below `./domains/`, as `require_glob()`
|
||||
is called in the subfolder `domains/`.
|
||||
|
Reference in New Issue
Block a user