ecto 4.1.4 → 4.2.0
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 +14 -4
- package/dist/ecto.d.ts +32 -2
- package/dist/ecto.js +20 -10
- package/package.json +15 -19
package/README.md
CHANGED
|
@@ -131,14 +131,23 @@ const ecto = new Ecto();
|
|
|
131
131
|
//ecto.<API> -- functions and parameters
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
+
There are a couple of options that can be passed to the Ecto constructor:
|
|
135
|
+
|
|
136
|
+
| Name | Type | Description |
|
|
137
|
+
| ---------------- | ------ | ------------------------------------------------------------ |
|
|
138
|
+
| defaultEngine | string | This is the default engine to use if it is not set when doing rendering |
|
|
139
|
+
| engineOptions | Record<stirng, Record<string, unknown>> | The options for each engin that you can set initially. |
|
|
140
|
+
|
|
141
|
+
here is an example of setting the default engine and also options for `nunjucks`:
|
|
142
|
+
|
|
143
|
+
```javascript
|
|
144
|
+
const ecto = new Ecto({defaultEngine: "nunjucks", engineOptions: {nunjucks: {autoescape: true}});
|
|
145
|
+
```
|
|
146
|
+
|
|
134
147
|
When looking at the API there are two main methods to make note of:
|
|
135
148
|
[render](#render-from-string) (async) - Render from a string.
|
|
136
149
|
[renderFromFile](#render-from-file) (async) - Renders from a file path and will auto-select what engine to use based on the file extension. It will return a `Promise<string>` of the rendered output.
|
|
137
150
|
|
|
138
|
-
Two key parameters to know are:
|
|
139
|
-
defaultEngine:string - the [default engine](#default-engine) to use and set by default to ejs.
|
|
140
|
-
mappings:EngineMap - [Mapping class](#mappings) of all the engines registered in the system.
|
|
141
|
-
|
|
142
151
|
## Render From String
|
|
143
152
|
|
|
144
153
|
As we have shown in [Getting Started -- It's that Easy!](#getting-started) You can render in only a couple of lines of code.
|
|
@@ -557,6 +566,7 @@ Ecto has added in some helper functions for frontmatter in markdown files. Front
|
|
|
557
566
|
|
|
558
567
|
* `.hasFrontMatter(source: string): boolean` - This function checks if the markdown file has frontmatter. It takes in a string and returns a boolean value.
|
|
559
568
|
* `.getFrontMatter(source: string): object` - This function gets the frontmatter from the markdown file. It takes in a string and returns an object.
|
|
569
|
+
* `setFrontMatter(source:string, data: Record<string, unknown>)` - This function sets the front matter even if it already exists and returns the full source with the new front matter.
|
|
560
570
|
* `.removeFrontMatter(source: string): string` - This function removes the frontmatter from the markdown file. It takes in a string and returns a string.
|
|
561
571
|
|
|
562
572
|
# How to Contribute
|
package/dist/ecto.d.ts
CHANGED
|
@@ -66,6 +66,29 @@ declare class Liquid extends BaseEngine implements EngineInterface {
|
|
|
66
66
|
renderSync(source: string, data?: Record<string, unknown>): string;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
type EctoOptions = {
|
|
70
|
+
/**
|
|
71
|
+
* The default engine to use. This can be 'ejs', 'markdown', 'pug', 'nunjucks', 'handlebars', 'liquid'
|
|
72
|
+
* @default 'ejs'
|
|
73
|
+
* @type {string}
|
|
74
|
+
*/
|
|
75
|
+
defaultEngine?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The engine options to pass to each engine
|
|
78
|
+
* @type {Record<string, Record<string, unknown>>}
|
|
79
|
+
* @default {}
|
|
80
|
+
* @example
|
|
81
|
+
* {
|
|
82
|
+
* nunjucks: {
|
|
83
|
+
* autoescape: true
|
|
84
|
+
* },
|
|
85
|
+
* markdown: {
|
|
86
|
+
* html: true
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
*/
|
|
90
|
+
engineOptions?: Record<string, Record<string, unknown>>;
|
|
91
|
+
};
|
|
69
92
|
declare class Ecto {
|
|
70
93
|
private readonly __mapping;
|
|
71
94
|
private readonly __engines;
|
|
@@ -76,7 +99,7 @@ declare class Ecto {
|
|
|
76
99
|
private readonly __nunjucks;
|
|
77
100
|
private readonly __handlebars;
|
|
78
101
|
private readonly __liquid;
|
|
79
|
-
constructor(options?:
|
|
102
|
+
constructor(options?: EctoOptions);
|
|
80
103
|
/**
|
|
81
104
|
* Get the default engine
|
|
82
105
|
*/
|
|
@@ -222,6 +245,13 @@ declare class Ecto {
|
|
|
222
245
|
* @returns {Record<string, unknown>}
|
|
223
246
|
*/
|
|
224
247
|
getFrontMatter(source: string): Record<string, unknown>;
|
|
248
|
+
/**
|
|
249
|
+
* Will set the front matter in the source and return the source
|
|
250
|
+
* @param {string} source - The source to set the front matter
|
|
251
|
+
* @param {Record<string, unknown>} data - The front matter data
|
|
252
|
+
* @returns {string} - The source with the front matter
|
|
253
|
+
*/
|
|
254
|
+
setFrontMatter(source: string, data: Record<string, unknown>): string;
|
|
225
255
|
/**
|
|
226
256
|
* Remove the Front Matter from the source
|
|
227
257
|
* @param {string} source
|
|
@@ -232,4 +262,4 @@ declare class Ecto {
|
|
|
232
262
|
private writeFileSync;
|
|
233
263
|
}
|
|
234
264
|
|
|
235
|
-
export { Ecto };
|
|
265
|
+
export { Ecto, type EctoOptions };
|
package/dist/ecto.js
CHANGED
|
@@ -103,14 +103,15 @@ var Markdown = class extends BaseEngine {
|
|
|
103
103
|
// src/engines/handlebars.ts
|
|
104
104
|
import fs from "node:fs";
|
|
105
105
|
import * as _ from "underscore";
|
|
106
|
-
import
|
|
106
|
+
import { helpers, handlebars } from "@jaredwray/fumanchu";
|
|
107
107
|
var Handlebars = class extends BaseEngine {
|
|
108
108
|
partialsPath = ["partials", "includes", "templates"];
|
|
109
109
|
constructor(options) {
|
|
110
110
|
super();
|
|
111
111
|
this.names = ["handlebars", "mustache"];
|
|
112
112
|
this.opts = options;
|
|
113
|
-
this.engine =
|
|
113
|
+
this.engine = handlebars;
|
|
114
|
+
helpers({ handlebars }, this.opts);
|
|
114
115
|
this.setExtensions(["hbs", "hjs", "handlebars", "mustache"]);
|
|
115
116
|
}
|
|
116
117
|
async render(source, data) {
|
|
@@ -299,14 +300,12 @@ var Ecto = class {
|
|
|
299
300
|
__handlebars;
|
|
300
301
|
__liquid;
|
|
301
302
|
constructor(options) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.
|
|
305
|
-
this.
|
|
306
|
-
this.
|
|
307
|
-
this.
|
|
308
|
-
this.__handlebars = new Handlebars(engineOptions);
|
|
309
|
-
this.__liquid = new Liquid(engineOptions);
|
|
303
|
+
this.__ejs = new EJS(options?.engineOptions?.ejs);
|
|
304
|
+
this.__markdown = new Markdown(options?.engineOptions?.markdown);
|
|
305
|
+
this.__pug = new Pug(options?.engineOptions?.pug);
|
|
306
|
+
this.__nunjucks = new Nunjucks(options?.engineOptions?.nunjucks);
|
|
307
|
+
this.__handlebars = new Handlebars(options?.engineOptions?.handlebars);
|
|
308
|
+
this.__liquid = new Liquid(options?.engineOptions?.liquid);
|
|
310
309
|
this.__engines.push(this.__ejs, this.__markdown, this.__pug, this.__nunjucks, this.__handlebars, this.__liquid);
|
|
311
310
|
this.registerEngineMappings();
|
|
312
311
|
if (options !== void 0 && this.isValidEngine(options.defaultEngine)) {
|
|
@@ -616,6 +615,17 @@ var Ecto = class {
|
|
|
616
615
|
const writr = new Writr2(source);
|
|
617
616
|
return writr.frontMatter;
|
|
618
617
|
}
|
|
618
|
+
/**
|
|
619
|
+
* Will set the front matter in the source and return the source
|
|
620
|
+
* @param {string} source - The source to set the front matter
|
|
621
|
+
* @param {Record<string, unknown>} data - The front matter data
|
|
622
|
+
* @returns {string} - The source with the front matter
|
|
623
|
+
*/
|
|
624
|
+
setFrontMatter(source, data) {
|
|
625
|
+
const writr = new Writr2(source);
|
|
626
|
+
writr.frontMatter = data;
|
|
627
|
+
return writr.content;
|
|
628
|
+
}
|
|
619
629
|
/**
|
|
620
630
|
* Remove the Front Matter from the source
|
|
621
631
|
* @param {string} source
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ecto",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Modern Template Consolidation Engine for EJS, Markdown, Pug, Nunjucks, Liquid, and Handlebars",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/ecto.js",
|
|
@@ -21,9 +21,8 @@
|
|
|
21
21
|
"watch": "tsc -w -p .",
|
|
22
22
|
"clean": "rimraf ./dist yarn.lock package-lock.json pnpm-lock.yaml ./coverage ./node_modules ./site/readme.md ./dist-site",
|
|
23
23
|
"test": "xo --fix && vitest run --coverage",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"prepare": "rimraf ./dist && npm run compile",
|
|
24
|
+
"build": "rimraf ./dist && tsup src/ecto.ts --format esm --dts --clean",
|
|
25
|
+
"prepare": "npm run build",
|
|
27
26
|
"website:build": "rimraf ./site/readme.md && npx -y docula build -s ./site -o ./dist-site",
|
|
28
27
|
"website:serve": "rimraf ./site/readme.md && npx -y docula serve -s ./site -o ./dist-site"
|
|
29
28
|
},
|
|
@@ -48,37 +47,34 @@
|
|
|
48
47
|
"liquidjs"
|
|
49
48
|
],
|
|
50
49
|
"dependencies": {
|
|
51
|
-
"@jaredwray/fumanchu": "^
|
|
50
|
+
"@jaredwray/fumanchu": "^3.0.3",
|
|
52
51
|
"ejs": "^3.1.10",
|
|
53
|
-
"liquidjs": "^10.
|
|
52
|
+
"liquidjs": "^10.20.2",
|
|
54
53
|
"nunjucks": "^3.2.4",
|
|
55
54
|
"pug": "^3.0.3",
|
|
56
55
|
"underscore": "^1.13.7",
|
|
57
|
-
"writr": "^4.
|
|
56
|
+
"writr": "^4.4.0"
|
|
58
57
|
},
|
|
59
58
|
"devDependencies": {
|
|
60
59
|
"@types/ejs": "^3.1.5",
|
|
61
60
|
"@types/express": "^5.0.0",
|
|
62
|
-
"@types/node": "^22.
|
|
61
|
+
"@types/node": "^22.13.0",
|
|
63
62
|
"@types/nunjucks": "^3.2.6",
|
|
64
63
|
"@types/pug": "^2.0.10",
|
|
65
64
|
"@types/underscore": "^1.13.0",
|
|
66
|
-
"@vitest/coverage-v8": "^
|
|
67
|
-
"docula": "^0.
|
|
65
|
+
"@vitest/coverage-v8": "^3.0.4",
|
|
66
|
+
"docula": "^0.10.0",
|
|
68
67
|
"rimraf": "^6.0.1",
|
|
69
|
-
"tsup": "^8.3.
|
|
70
|
-
"typescript": "^5.7.
|
|
71
|
-
"vitest": "^
|
|
72
|
-
"webpack": "^5.
|
|
73
|
-
"xo": "^0.
|
|
68
|
+
"tsup": "^8.3.6",
|
|
69
|
+
"typescript": "^5.7.3",
|
|
70
|
+
"vitest": "^3.0.4",
|
|
71
|
+
"webpack": "^5.97.1",
|
|
72
|
+
"xo": "^0.60.0"
|
|
74
73
|
},
|
|
75
74
|
"xo": {
|
|
76
75
|
"ignores": [
|
|
77
76
|
"vitest.config.mjs"
|
|
78
|
-
]
|
|
79
|
-
"rules": {
|
|
80
|
-
"n/file-extension-in-import": "off"
|
|
81
|
-
}
|
|
77
|
+
]
|
|
82
78
|
},
|
|
83
79
|
"files": [
|
|
84
80
|
"dist",
|