@rse/nunjucks-cli 1.2.0 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/nunjucks.d/pad.js +24 -0
- package/nunjucks.d/sprintf.js +21 -0
- package/nunjucks.d/uuid.js +14 -0
- package/nunjucks.js +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -52,7 +52,7 @@ $ nunjucks
|
|
|
52
52
|
load context definition YAML file.
|
|
53
53
|
- `-D`|`--define` `<key>=<value>`:<br/>
|
|
54
54
|
set context definition key/value.
|
|
55
|
-
- `-e`|`--extension` `default|date|eval|jsonpath|<module-name>`:<br/>
|
|
55
|
+
- `-e`|`--extension` `default|date|eval|jsonpath|pad|sprintf|uuid|<module-name>`:<br/>
|
|
56
56
|
load Nunjucks JavaScript extension module (built-in or NPM installed).
|
|
57
57
|
- `-o`|`--output` `<output-file>`|`-`:<br/>
|
|
58
58
|
save output file (or stdout).
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
3
|
+
** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
4
|
+
** Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
module.exports = (env) => {
|
|
8
|
+
/* add a "pad" formatting filter */
|
|
9
|
+
env.addFilter("pad", (input, num, char = " ", toRight = false) => {
|
|
10
|
+
if (typeof input !== "string") {
|
|
11
|
+
if (typeof input.toString === "function")
|
|
12
|
+
input = input.toString()
|
|
13
|
+
else
|
|
14
|
+
input = input + ''
|
|
15
|
+
}
|
|
16
|
+
let result = input
|
|
17
|
+
if (result.length < num) {
|
|
18
|
+
const pad = (new Array(num - result.length + 1)).join(char)
|
|
19
|
+
result = toRight ? result + pad : pad + result
|
|
20
|
+
}
|
|
21
|
+
return result
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
3
|
+
** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
4
|
+
** Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const sprintf = require("sprintfjs")
|
|
8
|
+
|
|
9
|
+
module.exports = (env) => {
|
|
10
|
+
/* add a "sprintf" formatting filter */
|
|
11
|
+
env.addFilter("sprintf", (value, format, ...args) => {
|
|
12
|
+
return sprintf(format, value, ...args)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
/* add a "sprintf" global function */
|
|
16
|
+
env.addGlobal("sprintf", (format, ...args) => {
|
|
17
|
+
console.log(format, args)
|
|
18
|
+
return sprintf(format, ...args)
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
** nunjucks -- Nunjucks Template Rendering Command-Line Interface
|
|
3
|
+
** Copyright (c) 2019-2023 Dr. Ralf S. Engelschall <http://engelschall.com>
|
|
4
|
+
** Licensed under MIT <http://spdx.org/licenses/MIT.html>
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const UUID = require("pure-uuid")
|
|
8
|
+
|
|
9
|
+
module.exports = (env) => {
|
|
10
|
+
env.addGlobal("uuid", (...args) => {
|
|
11
|
+
return (new UUID(...args)).format()
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
package/nunjucks.js
CHANGED
|
@@ -139,7 +139,7 @@ const env = nunjucks.configure(inputFile, options)
|
|
|
139
139
|
/* load external extension files */
|
|
140
140
|
if (typeof argv.extension === "object" && argv.extension instanceof Array) {
|
|
141
141
|
for (let extension of argv.extension) {
|
|
142
|
-
if (extension.match(/^(?:default|date|eval|jsonpath)$/))
|
|
142
|
+
if (extension.match(/^(?:default|date|eval|jsonpath|pad|sprintf|uuid)$/))
|
|
143
143
|
extension = path.join(__dirname, "nunjucks.d", `${extension}.js`)
|
|
144
144
|
let modpath = null
|
|
145
145
|
try {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rse/nunjucks-cli",
|
|
3
3
|
"publishConfig": { "access": "public" },
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"description": "Nunjucks Template Rendering Command-Line Interface",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Dr. Ralf S. Engelschall",
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
"moment": "2.29.4",
|
|
20
20
|
"moment-timezone": "0.5.43",
|
|
21
21
|
"jsonpath": "1.1.1",
|
|
22
|
+
"sprintfjs": "1.2.17",
|
|
23
|
+
"pure-uuid": "1.7.0",
|
|
22
24
|
"js-yaml": "4.1.0"
|
|
23
25
|
},
|
|
24
26
|
"devDependencies": {
|