@h3ravel/view 0.1.1 → 0.1.2

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.d.mts CHANGED
@@ -2,6 +2,23 @@
2
2
  import { Edge } from "edge.js";
3
3
  import { ServiceProvider } from "@h3ravel/core";
4
4
 
5
+ //#region src/Commands/MakeViewCommand.d.ts
6
+ /**
7
+ * Command to create new view files
8
+ */
9
+ declare class MakeViewCommand {
10
+ /**
11
+ * Create a new view file
12
+ *
13
+ * @param name - View name (can include directories like 'auth/login')
14
+ * @param options - Command options
15
+ */
16
+ static make(name: string, options?: {
17
+ force?: boolean;
18
+ basePath?: string;
19
+ }): Promise<void>;
20
+ }
21
+ //#endregion
5
22
  //#region src/Contracts/ViewContract.d.ts
6
23
  /**
7
24
  * Contract for view rendering engines
@@ -81,22 +98,5 @@ declare class ViewServiceProvider extends ServiceProvider {
81
98
  boot(): Promise<void>;
82
99
  }
83
100
  //#endregion
84
- //#region src/Commands/MakeViewCommand.d.ts
85
- /**
86
- * Command to create new view files
87
- */
88
- declare class MakeViewCommand {
89
- /**
90
- * Create a new view file
91
- *
92
- * @param name - View name (can include directories like 'auth/login')
93
- * @param options - Command options
94
- */
95
- static make(name: string, options?: {
96
- force?: boolean;
97
- basePath?: string;
98
- }): Promise<void>;
99
- }
100
- //#endregion
101
101
  export { EdgeViewEngine, MakeViewCommand, type ViewContract, EdgeViewEngine as ViewManager, ViewServiceProvider };
102
102
  //# sourceMappingURL=index.d.mts.map
package/dist/index.d.ts CHANGED
@@ -2,6 +2,23 @@
2
2
  import { Edge } from "edge.js";
3
3
  import { ServiceProvider } from "@h3ravel/core";
4
4
 
5
+ //#region src/Commands/MakeViewCommand.d.ts
6
+ /**
7
+ * Command to create new view files
8
+ */
9
+ declare class MakeViewCommand {
10
+ /**
11
+ * Create a new view file
12
+ *
13
+ * @param name - View name (can include directories like 'auth/login')
14
+ * @param options - Command options
15
+ */
16
+ static make(name: string, options?: {
17
+ force?: boolean;
18
+ basePath?: string;
19
+ }): Promise<void>;
20
+ }
21
+ //#endregion
5
22
  //#region src/Contracts/ViewContract.d.ts
6
23
  /**
7
24
  * Contract for view rendering engines
@@ -81,22 +98,5 @@ declare class ViewServiceProvider extends ServiceProvider {
81
98
  boot(): Promise<void>;
82
99
  }
83
100
  //#endregion
84
- //#region src/Commands/MakeViewCommand.d.ts
85
- /**
86
- * Command to create new view files
87
- */
88
- declare class MakeViewCommand {
89
- /**
90
- * Create a new view file
91
- *
92
- * @param name - View name (can include directories like 'auth/login')
93
- * @param options - Command options
94
- */
95
- static make(name: string, options?: {
96
- force?: boolean;
97
- basePath?: string;
98
- }): Promise<void>;
99
- }
100
- //#endregion
101
101
  export { EdgeViewEngine, MakeViewCommand, type ViewContract, EdgeViewEngine as ViewManager, ViewServiceProvider };
102
102
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -21,15 +21,45 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  }) : target, mod));
22
22
 
23
23
  //#endregion
24
- let edge_js = require("edge.js");
25
- edge_js = __toESM(edge_js);
26
- let __h3ravel_core = require("@h3ravel/core");
27
- __h3ravel_core = __toESM(__h3ravel_core);
28
24
  let node_fs_promises = require("node:fs/promises");
29
25
  node_fs_promises = __toESM(node_fs_promises);
30
26
  let node_path = require("node:path");
31
27
  node_path = __toESM(node_path);
28
+ let edge_js = require("edge.js");
29
+ edge_js = __toESM(edge_js);
30
+ let __h3ravel_core = require("@h3ravel/core");
31
+ __h3ravel_core = __toESM(__h3ravel_core);
32
+
33
+ //#region src/Commands/MakeViewCommand.ts
34
+ /**
35
+ * Command to create new view files
36
+ */
37
+ var MakeViewCommand = class {
38
+ /**
39
+ * Create a new view file
40
+ *
41
+ * @param name - View name (can include directories like 'auth/login')
42
+ * @param options - Command options
43
+ */
44
+ static async make(name, options = {}) {
45
+ const { force = false, basePath = "src/resources/views" } = options;
46
+ const path = `${basePath}/${name}.edge`;
47
+ if (name.includes("/")) await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
48
+ if (!force) try {
49
+ const { FileSystem } = await import("@h3ravel/shared");
50
+ if (await FileSystem.fileExists(path)) throw new Error(`View ${name} already exists`);
51
+ } catch (error) {
52
+ if (error instanceof Error && error.message.includes("already exists")) throw error;
53
+ }
54
+ await (0, node_fs_promises.writeFile)(path, `{{-- ${path} --}}
55
+ <div>
56
+ <!-- Your view content here -->
57
+ <h1>{{ title ?? 'Welcome' }}</h1>
58
+ </div>`);
59
+ }
60
+ };
32
61
 
62
+ //#endregion
33
63
  //#region src/EdgeViewEngine.ts
34
64
  /**
35
65
  * Edge.js implementation of the ViewContract
@@ -120,37 +150,6 @@ var ViewServiceProvider = class extends __h3ravel_core.ServiceProvider {
120
150
  }
121
151
  };
122
152
 
123
- //#endregion
124
- //#region src/Commands/MakeViewCommand.ts
125
- /**
126
- * Command to create new view files
127
- */
128
- var MakeViewCommand = class {
129
- /**
130
- * Create a new view file
131
- *
132
- * @param name - View name (can include directories like 'auth/login')
133
- * @param options - Command options
134
- */
135
- static async make(name, options = {}) {
136
- const { force = false, basePath = "src/resources/views" } = options;
137
- const path = `${basePath}/${name}.edge`;
138
- if (name.includes("/")) await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
139
- if (!force) try {
140
- const { FileSystem } = await import("@h3ravel/shared");
141
- if (await FileSystem.fileExists(path)) throw new Error(`View ${name} already exists`);
142
- } catch (error) {
143
- if (error instanceof Error && error.message.includes("already exists")) throw error;
144
- }
145
- const content = `{{-- ${path} --}}
146
- <div>
147
- <!-- Your view content here -->
148
- <h1>{{ title ?? 'Welcome' }}</h1>
149
- </div>`;
150
- await (0, node_fs_promises.writeFile)(path, content);
151
- }
152
- };
153
-
154
153
  //#endregion
155
154
  exports.EdgeViewEngine = EdgeViewEngine;
156
155
  exports.MakeViewCommand = MakeViewCommand;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Edge","ServiceProvider"],"sources":["../src/EdgeViewEngine.ts","../src/Providers/ViewServiceProvider.ts","../src/Commands/MakeViewCommand.ts"],"sourcesContent":["import { Edge } from 'edge.js'\nimport { ViewContract } from './Contracts/ViewContract'\n\n/**\n * Edge.js implementation of the ViewContract\n */\nexport class EdgeViewEngine implements ViewContract {\n private edge: Edge\n\n constructor(options: {\n viewsPath?: string\n cache?: boolean\n } = {}) {\n this.edge = Edge.create({\n cache: options.cache ?? false\n })\n\n if (options.viewsPath) {\n this.edge.mount(options.viewsPath)\n }\n }\n\n /**\n * Render a template with the given data\n */\n async render (template: string, data: Record<string, any> = {}): Promise<string> {\n return await this.edge.render(template, data)\n }\n\n /**\n * Check if a template exists\n */\n exists (_template: string): boolean {\n try {\n // Edge doesn't have a direct exists method, so we try to render with empty data\n // This is a simple approach - in production you might want to implement proper template discovery\n return true // For now, assume template exists - Edge will throw if it doesn't during render\n } catch {\n return false\n }\n }\n\n /**\n * Mount a directory for template lookup\n */\n mount (path: string): void {\n this.edge.mount(path)\n }\n\n /**\n * Register a global variable/helper\n */\n global (key: string, value: any): void {\n this.edge.global(key, value)\n }\n\n /**\n * Get the underlying Edge instance\n */\n getEdge (): Edge {\n return this.edge\n }\n}\n","import { EdgeViewEngine } from '../EdgeViewEngine'\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * View Service Provider\n * \n * Registers the view engine with the application container\n */\nexport class ViewServiceProvider extends ServiceProvider {\n public static priority = 995\n\n async register () {\n // Create the view engine instance\n const viewEngine = new EdgeViewEngine({\n viewsPath: this.app.getPath('views'),\n cache: process.env.NODE_ENV === 'production'\n })\n\n // Register the app instance if available\n viewEngine.global('app', this.app)\n\n const edge = viewEngine.getEdge()\n\n /**\n * Bind the view engine to the container\n */\n this.app.bind('edge', () => edge)\n }\n\n async boot () {\n /**\n * Initialize the view handler method\n * \n * @param template \n * @param params \n * @returns \n */\n const view = async (template: string, data?: Record<string, any>) => {\n const response = this.app.make('http.response')\n\n return response.html(await this.app.make('edge').render(template, data))\n }\n\n /**\n * Bind the view method to the global variable space\n */\n globalThis.view = view\n\n /**\n * Dynamically bind the view renderer to the service container.\n * This allows any part of the request lifecycle to render templates using Edge.\n */\n this.app.bind('view', () => view)\n }\n}\n","import { mkdir, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\n\n/**\n * Command to create new view files\n */\nexport class MakeViewCommand {\n /**\n * Create a new view file\n * \n * @param name - View name (can include directories like 'auth/login')\n * @param options - Command options\n */\n static async make(\n name: string, \n options: {\n force?: boolean\n basePath?: string\n } = {}\n ): Promise<void> {\n const { force = false, basePath = 'src/resources/views' } = options\n \n const path = `${basePath}/${name}.edge`\n\n // The view is scoped to a path make sure to create the associated directories\n if (name.includes('/')) {\n await mkdir(dirname(path), { recursive: true })\n }\n\n // Check if the view already exists\n if (!force) {\n try {\n const { FileSystem } = await import('@h3ravel/shared')\n if (await FileSystem.fileExists(path)) {\n throw new Error(`View ${name} already exists`)\n }\n } catch (error) {\n if (error instanceof Error && error.message.includes('already exists')) {\n throw error\n }\n // FileSystem not available, continue\n }\n }\n\n // Create the view file\n const content = `{{-- ${path} --}}\n<div>\n <!-- Your view content here -->\n <h1>{{ title ?? 'Welcome' }}</h1>\n</div>`\n\n await writeFile(path, content)\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,iBAAb,MAAoD;CAClD,AAAQ;CAER,YAAY,UAGR,EAAE,EAAE;AACN,OAAK,OAAOA,aAAK,OAAO,EACtB,OAAO,QAAQ,SAAS,OACzB,CAAC;AAEF,MAAI,QAAQ,UACV,MAAK,KAAK,MAAM,QAAQ,UAAU;;;;;CAOtC,MAAM,OAAQ,UAAkB,OAA4B,EAAE,EAAmB;AAC/E,SAAO,MAAM,KAAK,KAAK,OAAO,UAAU,KAAK;;;;;CAM/C,OAAQ,WAA4B;AAClC,MAAI;AAGF,UAAO;UACD;AACN,UAAO;;;;;;C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M7B,wCAAgB,MAAM,QAAQ"}
1
+ {"version":3,"file":"index.js","names":["Edge","ServiceProvider"],"sources":["../src/Commands/MakeViewCommand.ts","../src/EdgeViewEngine.ts","../src/Providers/ViewServiceProvider.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\n\n/**\n * Command to create new view files\n */\nexport class MakeViewCommand {\n /**\n * Create a new view file\n * \n * @param name - View name (can include directories like 'auth/login')\n * @param options - Command options\n */\n static async make(\n name: string, \n options: {\n force?: boolean\n basePath?: string\n } = {}\n ): Promise<void> {\n const { force = false, basePath = 'src/resources/views' } = options\n \n const path = `${basePath}/${name}.edge`\n\n // The view is scoped to a path make sure to create the associated directories\n if (name.includes('/')) {\n await mkdir(dirname(path), { recursive: true })\n }\n\n // Check if the view already exists\n if (!force) {\n try {\n const { FileSystem } = await import('@h3ravel/shared')\n if (await FileSystem.fileExists(path)) {\n throw new Error(`View ${name} already exists`)\n }\n } catch (error) {\n if (error instanceof Error && error.message.includes('already exists')) {\n throw error\n }\n // FileSystem not available, continue\n }\n }\n\n // Create the view file\n const content = `{{-- ${path} --}}\n<div>\n <!-- Your view content here -->\n <h1>{{ title ?? 'Welcome' }}</h1>\n</div>`\n\n await writeFile(path, content)\n }\n}","import { Edge } from 'edge.js'\nimport { ViewContract } from './Contracts/ViewContract'\n\n/**\n * Edge.js implementation of the ViewContract\n */\nexport class EdgeViewEngine implements ViewContract {\n private edge: Edge\n\n constructor(options: {\n viewsPath?: string\n cache?: boolean\n } = {}) {\n this.edge = Edge.create({\n cache: options.cache ?? false\n })\n\n if (options.viewsPath) {\n this.edge.mount(options.viewsPath)\n }\n }\n\n /**\n * Render a template with the given data\n */\n async render (template: string, data: Record<string, any> = {}): Promise<string> {\n return await this.edge.render(template, data)\n }\n\n /**\n * Check if a template exists\n */\n exists (_template: string): boolean {\n try {\n // Edge doesn't have a direct exists method, so we try to render with empty data\n // This is a simple approach - in production you might want to implement proper template discovery\n return true // For now, assume template exists - Edge will throw if it doesn't during render\n } catch {\n return false\n }\n }\n\n /**\n * Mount a directory for template lookup\n */\n mount (path: string): void {\n this.edge.mount(path)\n }\n\n /**\n * Register a global variable/helper\n */\n global (key: string, value: any): void {\n this.edge.global(key, value)\n }\n\n /**\n * Get the underlying Edge instance\n */\n getEdge (): Edge {\n return this.edge\n }\n}\n","import { EdgeViewEngine } from '../EdgeViewEngine'\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * View Service Provider\n * \n * Registers the view engine with the application container\n */\nexport class ViewServiceProvider extends ServiceProvider {\n public static priority = 995\n\n async register () {\n // Create the view engine instance\n const viewEngine = new EdgeViewEngine({\n viewsPath: this.app.getPath('views'),\n cache: process.env.NODE_ENV === 'production'\n })\n\n // Register the app instance if available\n viewEngine.global('app', this.app)\n\n const edge = viewEngine.getEdge()\n\n /**\n * Bind the view engine to the container\n */\n this.app.bind('edge', () => edge)\n }\n\n async boot () {\n /**\n * Initialize the view handler method\n * \n * @param template \n * @param params \n * @returns \n */\n const view = async (template: string, data?: Record<string, any>) => {\n const response = this.app.make('http.response')\n\n return response.html(await this.app.make('edge').render(template, data))\n }\n\n /**\n * Bind the view method to the global variable space\n */\n globalThis.view = view\n\n /**\n * Dynamically bind the view renderer to the service container.\n * This allows any part of the request lifecycle to render templates using Edge.\n */\n this.app.bind('view', () => view)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,IAAa,kBAAb,MAA6B;;;;;;;CAO3B,aAAa,KACX,MACA,UAGI,EAAE,EACS;EACf,MAAM,EAAE,QAAQ,OAAO,WAAW,0BAA0B;EAE5D,MAAM,OAAO,GAAG,SAAS,GAAG,KAAK;AAGjC,MAAI,KAAK,SAAS,IAAI,CACpB,0DAAoB,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AAIjD,MAAI,CAAC,MACH,KAAI;GACF,MAAM,EAAE,eAAe,MAAM,OAAO;AACpC,OAAI,MAAM,WAAW,WAA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MlB,OAAK,IAAI,KAAK,cAAc,KAAK"}
package/dist/index.mjs CHANGED
@@ -1,8 +1,38 @@
1
- import { Edge } from "edge.js";
2
- import { ServiceProvider } from "@h3ravel/core";
3
1
  import { mkdir, writeFile } from "node:fs/promises";
4
2
  import { dirname } from "node:path";
3
+ import { Edge } from "edge.js";
4
+ import { ServiceProvider } from "@h3ravel/core";
5
+
6
+ //#region src/Commands/MakeViewCommand.ts
7
+ /**
8
+ * Command to create new view files
9
+ */
10
+ var MakeViewCommand = class {
11
+ /**
12
+ * Create a new view file
13
+ *
14
+ * @param name - View name (can include directories like 'auth/login')
15
+ * @param options - Command options
16
+ */
17
+ static async make(name, options = {}) {
18
+ const { force = false, basePath = "src/resources/views" } = options;
19
+ const path = `${basePath}/${name}.edge`;
20
+ if (name.includes("/")) await mkdir(dirname(path), { recursive: true });
21
+ if (!force) try {
22
+ const { FileSystem } = await import("@h3ravel/shared");
23
+ if (await FileSystem.fileExists(path)) throw new Error(`View ${name} already exists`);
24
+ } catch (error) {
25
+ if (error instanceof Error && error.message.includes("already exists")) throw error;
26
+ }
27
+ await writeFile(path, `{{-- ${path} --}}
28
+ <div>
29
+ <!-- Your view content here -->
30
+ <h1>{{ title ?? 'Welcome' }}</h1>
31
+ </div>`);
32
+ }
33
+ };
5
34
 
35
+ //#endregion
6
36
  //#region src/EdgeViewEngine.ts
7
37
  /**
8
38
  * Edge.js implementation of the ViewContract
@@ -93,37 +123,6 @@ var ViewServiceProvider = class extends ServiceProvider {
93
123
  }
94
124
  };
95
125
 
96
- //#endregion
97
- //#region src/Commands/MakeViewCommand.ts
98
- /**
99
- * Command to create new view files
100
- */
101
- var MakeViewCommand = class {
102
- /**
103
- * Create a new view file
104
- *
105
- * @param name - View name (can include directories like 'auth/login')
106
- * @param options - Command options
107
- */
108
- static async make(name, options = {}) {
109
- const { force = false, basePath = "src/resources/views" } = options;
110
- const path = `${basePath}/${name}.edge`;
111
- if (name.includes("/")) await mkdir(dirname(path), { recursive: true });
112
- if (!force) try {
113
- const { FileSystem } = await import("@h3ravel/shared");
114
- if (await FileSystem.fileExists(path)) throw new Error(`View ${name} already exists`);
115
- } catch (error) {
116
- if (error instanceof Error && error.message.includes("already exists")) throw error;
117
- }
118
- const content = `{{-- ${path} --}}
119
- <div>
120
- <!-- Your view content here -->
121
- <h1>{{ title ?? 'Welcome' }}</h1>
122
- </div>`;
123
- await writeFile(path, content);
124
- }
125
- };
126
-
127
126
  //#endregion
128
127
  export { EdgeViewEngine, MakeViewCommand, EdgeViewEngine as ViewManager, ViewServiceProvider };
129
128
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/EdgeViewEngine.ts","../src/Providers/ViewServiceProvider.ts","../src/Commands/MakeViewCommand.ts"],"sourcesContent":["import { Edge } from 'edge.js'\nimport { ViewContract } from './Contracts/ViewContract'\n\n/**\n * Edge.js implementation of the ViewContract\n */\nexport class EdgeViewEngine implements ViewContract {\n private edge: Edge\n\n constructor(options: {\n viewsPath?: string\n cache?: boolean\n } = {}) {\n this.edge = Edge.create({\n cache: options.cache ?? false\n })\n\n if (options.viewsPath) {\n this.edge.mount(options.viewsPath)\n }\n }\n\n /**\n * Render a template with the given data\n */\n async render (template: string, data: Record<string, any> = {}): Promise<string> {\n return await this.edge.render(template, data)\n }\n\n /**\n * Check if a template exists\n */\n exists (_template: string): boolean {\n try {\n // Edge doesn't have a direct exists method, so we try to render with empty data\n // This is a simple approach - in production you might want to implement proper template discovery\n return true // For now, assume template exists - Edge will throw if it doesn't during render\n } catch {\n return false\n }\n }\n\n /**\n * Mount a directory for template lookup\n */\n mount (path: string): void {\n this.edge.mount(path)\n }\n\n /**\n * Register a global variable/helper\n */\n global (key: string, value: any): void {\n this.edge.global(key, value)\n }\n\n /**\n * Get the underlying Edge instance\n */\n getEdge (): Edge {\n return this.edge\n }\n}\n","import { EdgeViewEngine } from '../EdgeViewEngine'\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * View Service Provider\n * \n * Registers the view engine with the application container\n */\nexport class ViewServiceProvider extends ServiceProvider {\n public static priority = 995\n\n async register () {\n // Create the view engine instance\n const viewEngine = new EdgeViewEngine({\n viewsPath: this.app.getPath('views'),\n cache: process.env.NODE_ENV === 'production'\n })\n\n // Register the app instance if available\n viewEngine.global('app', this.app)\n\n const edge = viewEngine.getEdge()\n\n /**\n * Bind the view engine to the container\n */\n this.app.bind('edge', () => edge)\n }\n\n async boot () {\n /**\n * Initialize the view handler method\n * \n * @param template \n * @param params \n * @returns \n */\n const view = async (template: string, data?: Record<string, any>) => {\n const response = this.app.make('http.response')\n\n return response.html(await this.app.make('edge').render(template, data))\n }\n\n /**\n * Bind the view method to the global variable space\n */\n globalThis.view = view\n\n /**\n * Dynamically bind the view renderer to the service container.\n * This allows any part of the request lifecycle to render templates using Edge.\n */\n this.app.bind('view', () => view)\n }\n}\n","import { mkdir, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\n\n/**\n * Command to create new view files\n */\nexport class MakeViewCommand {\n /**\n * Create a new view file\n * \n * @param name - View name (can include directories like 'auth/login')\n * @param options - Command options\n */\n static async make(\n name: string, \n options: {\n force?: boolean\n basePath?: string\n } = {}\n ): Promise<void> {\n const { force = false, basePath = 'src/resources/views' } = options\n \n const path = `${basePath}/${name}.edge`\n\n // The view is scoped to a path make sure to create the associated directories\n if (name.includes('/')) {\n await mkdir(dirname(path), { recursive: true })\n }\n\n // Check if the view already exists\n if (!force) {\n try {\n const { FileSystem } = await import('@h3ravel/shared')\n if (await FileSystem.fileExists(path)) {\n throw new Error(`View ${name} already exists`)\n }\n } catch (error) {\n if (error instanceof Error && error.message.includes('already exists')) {\n throw error\n }\n // FileSystem not available, continue\n }\n }\n\n // Create the view file\n const content = `{{-- ${path} --}}\n<div>\n <!-- Your view content here -->\n <h1>{{ title ?? 'Welcome' }}</h1>\n</div>`\n\n await writeFile(path, content)\n }\n}"],"mappings":";;;;;;;;;AAMA,IAAa,iBAA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AAGjC,MAAI,KAAK,SAAS,IAAI,CACpB,OAAM,MAAM,QAAQ,KAAK,EAAE,EAAE,WAAW,MAAM,CAAC;AAIjD,MAAI,CAAC,MACH,KAAI;GACF,MAAM,EAAE,eAAe,MAAM,OAAO;AACpC,OAAI,MAAM,WAAW,WAAW,KAAK,CACnC,OAAM,IAAI,MAAM,QAAQ,KAAK,iBAAiB;WAEzC,OAAO;AACd,OAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,iBAAiB,CACpE,OAAM;;EAOZ,MAAM,UAAU,QAAQ,KAAK;;;;;AAM7B,QAAM,UAAU,MAAM,QAAQ"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/Commands/MakeViewCommand.ts","../src/EdgeViewEngine.ts","../src/Providers/ViewServiceProvider.ts"],"sourcesContent":["import { mkdir, writeFile } from 'node:fs/promises'\nimport { dirname } from 'node:path'\n\n/**\n * Command to create new view files\n */\nexport class MakeViewCommand {\n /**\n * Create a new view file\n * \n * @param name - View name (can include directories like 'auth/login')\n * @param options - Command options\n */\n static async make(\n name: string, \n options: {\n force?: boolean\n basePath?: string\n } = {}\n ): Promise<void> {\n const { force = false, basePath = 'src/resources/views' } = options\n \n const path = `${basePath}/${name}.edge`\n\n // The view is scoped to a path make sure to create the associated directories\n if (name.includes('/')) {\n await mkdir(dirname(path), { recursive: true })\n }\n\n // Check if the view already exists\n if (!force) {\n try {\n const { FileSystem } = await import('@h3ravel/shared')\n if (await FileSystem.fileExists(path)) {\n throw new Error(`View ${name} already exists`)\n }\n } catch (error) {\n if (error instanceof Error && error.message.includes('already exists')) {\n throw error\n }\n // FileSystem not available, continue\n }\n }\n\n // Create the view file\n const content = `{{-- ${path} --}}\n<div>\n <!-- Your view content here -->\n <h1>{{ title ?? 'Welcome' }}</h1>\n</div>`\n\n await writeFile(path, content)\n }\n}","import { Edge } from 'edge.js'\nimport { ViewContract } from './Contracts/ViewContract'\n\n/**\n * Edge.js implementation of the ViewContract\n */\nexport class EdgeViewEngine implements ViewContract {\n private edge: Edge\n\n constructor(options: {\n viewsPath?: string\n cache?: boolean\n } = {}) {\n this.edge = Edge.create({\n cache: options.cache ?? false\n })\n\n if (options.viewsPath) {\n this.edge.mount(options.viewsPath)\n }\n }\n\n /**\n * Render a template with the given data\n */\n async render (template: string, data: Record<string, any> = {}): Promise<string> {\n return await this.edge.render(template, data)\n }\n\n /**\n * Check if a template exists\n */\n exists (_template: string): boolean {\n try {\n // Edge doesn't have a direct exists method, so we try to render with empty data\n // This is a simple approach - in production you might want to implement proper template discovery\n return true // For now, assume template exists - Edge will throw if it doesn't during render\n } catch {\n return false\n }\n }\n\n /**\n * Mount a directory for template lookup\n */\n mount (path: string): void {\n this.edge.mount(path)\n }\n\n /**\n * Register a global variable/helper\n */\n global (key: string, value: any): void {\n this.edge.global(key, value)\n }\n\n /**\n * Get the underlying Edge instance\n */\n getEdge (): Edge {\n return this.edge\n }\n}\n","import { EdgeViewEngine } from '../EdgeViewEngine'\nimport { ServiceProvider } from '@h3ravel/core'\n\n/**\n * View Service Provider\n * \n * Registers the view engine with the application container\n */\nexport class ViewServiceProvider extends ServiceProvider {\n public static priority = 995\n\n async register () {\n // Create the view engine instance\n const viewEngine = new EdgeViewEngine({\n viewsPath: this.app.getPath('views'),\n cache: process.env.NODE_ENV === 'production'\n })\n\n // Register the app instance if available\n viewEngine.global('app', this.app)\n\n const edge = viewEngine.getEdge()\n\n /**\n * Bind the view engine to the container\n */\n this.app.bind('edge', () => edge)\n }\n\n async boot () {\n /**\n * Initialize the view handler method\n * \n * @param template \n * @param params \n * @returns \n */\n const view = async (template: string, data?: Record<string, any>) => {\n const response = this.app.make('http.response')\n\n return response.html(await this.app.make('edge').render(template, data))\n }\n\n /**\n * Bind the view method to the global variable space\n */\n globalThis.view = view\n\n /**\n * Dynamically bind the view renderer to the service container.\n * This allows any part of the request lifecycle to render templates using Edge.\n */\n this.app.bind('view', () => view)\n }\n}\n"],"mappings":";;;;;;;;;AAMA,IAAa,kBAAb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,CAAC;AAGF,aAAW,OAAO,OAAO,KAAK,IAAI;EAElC,MAAM,OAAO,WAAW,SAAS;;;;AAKjC,OAAK,IAAI,KAAK,cAAc,KAAK;;CAGnC,MAAM,OAAQ;;;;;;;;EAQZ,MAAM,OAAO,OAAO,UAAkB,SAA+B;AAGnE,UAFiB,KAAK,IAAI,KAAK,gBAAgB,CAE/B,KAAK,MAAM,KAAK,IAAI,KAAK,OAAO,CAAC,OAAO,UAAU,KAAK,CAAC;;;;;AAM1E,aAAW,OAAO;;;;;AAMlB,OAAK,IAAI,KAAK,cAAc,KAAK"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h3ravel/view",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "View rendering system for H3ravel framework",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -38,15 +38,15 @@
38
38
  "homepage": "https://h3ravel.toneflix.net",
39
39
  "dependencies": {
40
40
  "edge.js": "^6.3.0",
41
- "@h3ravel/core": "1.12.0",
42
- "@h3ravel/http": "11.3.2"
41
+ "@h3ravel/core": "1.15.0",
42
+ "@h3ravel/http": "11.3.3"
43
43
  },
44
44
  "devDependencies": {
45
45
  "typescript": "^5.0.0",
46
46
  "vitest": "^2.0.0"
47
47
  },
48
48
  "peerDependencies": {
49
- "@h3ravel/shared": "0.20.11"
49
+ "@h3ravel/shared": "0.22.1"
50
50
  },
51
51
  "scripts": {
52
52
  "dev": "tsdown --watch --config-loader unconfig",