@wxn0brp/falcon-frame 0.5.1 → 0.5.3

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/dist/index.js CHANGED
@@ -27,9 +27,9 @@ export class FalconFrame extends Router {
27
27
  this.addBodyParser(json(this, { limit: this.opts.bodyLimit }));
28
28
  if (!this.opts.disableUrlencodedParser)
29
29
  this.addBodyParser(urlencoded(this, { limit: this.opts.bodyLimit }));
30
- this.engine(".html", (path, options, callback) => {
30
+ this.engine(".html", (path, options, callback, FF) => {
31
31
  try {
32
- const content = renderHTML(path, options);
32
+ const content = renderHTML(path, options, [], FF);
33
33
  callback(null, content);
34
34
  }
35
35
  catch (e) {
@@ -65,9 +65,8 @@ export class FalconFrame extends Router {
65
65
  };
66
66
  }
67
67
  engine(ext, callback) {
68
- if (ext[0] !== ".") {
68
+ if (ext[0] !== ".")
69
69
  ext = "." + ext;
70
- }
71
70
  this.engines[ext] = callback;
72
71
  return this;
73
72
  }
package/dist/render.js CHANGED
@@ -3,8 +3,13 @@ import path from "path";
3
3
  export function renderHTML(templatePath, data, renderedPaths = [], FF) {
4
4
  try {
5
5
  const realPath = path.resolve(templatePath);
6
- if (renderedPaths.includes(realPath)) {
6
+ if (renderedPaths.includes(realPath))
7
7
  return `<!-- Circular dependency detected: tried to render ${templatePath} again -->`;
8
+ if (FF && FF.vars["render data"]) {
9
+ data = {
10
+ ...FF.vars["render data"],
11
+ ...data,
12
+ };
8
13
  }
9
14
  let template = fs.readFileSync(templatePath, "utf8");
10
15
  // Inserting data, e.g. {{name}}
@@ -15,7 +20,7 @@ export function renderHTML(templatePath, data, renderedPaths = [], FF) {
15
20
  return renderHTML(partialPath, data, [
16
21
  ...renderedPaths,
17
22
  realPath,
18
- ]);
23
+ ], FF);
19
24
  });
20
25
  // Layout
21
26
  if (FF && FF.vars["layout"]) {
@@ -26,7 +31,7 @@ export function renderHTML(templatePath, data, renderedPaths = [], FF) {
26
31
  return template;
27
32
  if (!hasHtmlStructure && forceNoLayout)
28
33
  return template;
29
- return renderHTML(FF.vars["layout"], { ...data, body: template }, [...renderedPaths, realPath]);
34
+ return renderHTML(FF.vars["layout"], { ...data, body: template }, [...renderedPaths, realPath], FF);
30
35
  }
31
36
  return template;
32
37
  }
package/dist/res.js CHANGED
@@ -137,7 +137,7 @@ export class FFResponse extends http.ServerResponse {
137
137
  this.ct(opts.contentType || "text/html");
138
138
  this.end(str);
139
139
  }
140
- });
140
+ }, opts.notShareFF ? undefined : this.FF);
141
141
  }
142
142
  catch (err) {
143
143
  ff.logger.error(`Unhandled error in template engine: ${err}`);
package/dist/types.d.ts CHANGED
@@ -61,11 +61,12 @@ export interface StaticServeOptions {
61
61
  errorIfDirNotFound?: boolean;
62
62
  notRenderHtml?: boolean;
63
63
  }
64
- export type EngineCallback = (path: string, options: any, callback: (e: any, rendered?: string) => void) => void;
64
+ export type EngineCallback = (path: string, options: any, callback: (e: any, rendered?: string) => void, FF?: FalconFrame) => void;
65
65
  export interface RenderOptions {
66
66
  notUseViews?: boolean;
67
67
  contentType?: string;
68
68
  baseDir?: string;
69
69
  engine?: string;
70
70
  notAppendExt?: boolean;
71
+ notShareFF?: boolean;
71
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/falcon-frame",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": "wxn0brP",