ecto 4.1.5 → 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 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?: Record<string, unknown>);
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
@@ -300,14 +300,12 @@ var Ecto = class {
300
300
  __handlebars;
301
301
  __liquid;
302
302
  constructor(options) {
303
- const engineOptions = { ...options };
304
- delete engineOptions.defaultEngine;
305
- this.__ejs = new EJS(engineOptions);
306
- this.__markdown = new Markdown(engineOptions);
307
- this.__pug = new Pug(engineOptions);
308
- this.__nunjucks = new Nunjucks(engineOptions);
309
- this.__handlebars = new Handlebars(engineOptions);
310
- 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);
311
309
  this.__engines.push(this.__ejs, this.__markdown, this.__pug, this.__nunjucks, this.__handlebars, this.__liquid);
312
310
  this.registerEngineMappings();
313
311
  if (options !== void 0 && this.isValidEngine(options.defaultEngine)) {
@@ -617,6 +615,17 @@ var Ecto = class {
617
615
  const writr = new Writr2(source);
618
616
  return writr.frontMatter;
619
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
+ }
620
629
  /**
621
630
  * Remove the Front Matter from the source
622
631
  * @param {string} source
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ecto",
3
- "version": "4.1.5",
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",
@@ -47,27 +47,27 @@
47
47
  "liquidjs"
48
48
  ],
49
49
  "dependencies": {
50
- "@jaredwray/fumanchu": "^3.0.2",
50
+ "@jaredwray/fumanchu": "^3.0.3",
51
51
  "ejs": "^3.1.10",
52
- "liquidjs": "^10.20.0",
52
+ "liquidjs": "^10.20.2",
53
53
  "nunjucks": "^3.2.4",
54
54
  "pug": "^3.0.3",
55
55
  "underscore": "^1.13.7",
56
- "writr": "^4.3.0"
56
+ "writr": "^4.4.0"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/ejs": "^3.1.5",
60
60
  "@types/express": "^5.0.0",
61
- "@types/node": "^22.10.2",
61
+ "@types/node": "^22.13.0",
62
62
  "@types/nunjucks": "^3.2.6",
63
63
  "@types/pug": "^2.0.10",
64
64
  "@types/underscore": "^1.13.0",
65
- "@vitest/coverage-v8": "^2.1.8",
66
- "docula": "^0.9.6",
65
+ "@vitest/coverage-v8": "^3.0.4",
66
+ "docula": "^0.10.0",
67
67
  "rimraf": "^6.0.1",
68
- "tsup": "^8.3.5",
69
- "typescript": "^5.7.2",
70
- "vitest": "^2.1.8",
68
+ "tsup": "^8.3.6",
69
+ "typescript": "^5.7.3",
70
+ "vitest": "^3.0.4",
71
71
  "webpack": "^5.97.1",
72
72
  "xo": "^0.60.0"
73
73
  },