@h3ravel/view 0.1.3 → 0.1.5
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 +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -3
- package/dist/index.mjs +3 -3
- package/package.json +5 -4
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
+
import { Command } from "@h3ravel/musket";
|
|
2
3
|
import { Edge } from "edge.js";
|
|
3
4
|
import { ServiceProvider } from "@h3ravel/core";
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ import { ServiceProvider } from "@h3ravel/core";
|
|
|
6
7
|
/**
|
|
7
8
|
* Command to create new view files
|
|
8
9
|
*/
|
|
9
|
-
declare class MakeViewCommand {
|
|
10
|
+
declare class MakeViewCommand extends Command {
|
|
10
11
|
/**
|
|
11
12
|
* Create a new view file
|
|
12
13
|
*
|
|
@@ -98,5 +99,4 @@ declare class ViewServiceProvider extends ServiceProvider {
|
|
|
98
99
|
boot(): Promise<void>;
|
|
99
100
|
}
|
|
100
101
|
//#endregion
|
|
101
|
-
export { EdgeViewEngine, MakeViewCommand, type ViewContract, EdgeViewEngine as ViewManager, ViewServiceProvider };
|
|
102
|
-
//# sourceMappingURL=index.d.mts.map
|
|
102
|
+
export { EdgeViewEngine, MakeViewCommand, type ViewContract, EdgeViewEngine as ViewManager, ViewServiceProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
+
import { Command } from "@h3ravel/musket";
|
|
2
3
|
import { Edge } from "edge.js";
|
|
3
4
|
import { ServiceProvider } from "@h3ravel/core";
|
|
4
5
|
|
|
@@ -6,7 +7,7 @@ import { ServiceProvider } from "@h3ravel/core";
|
|
|
6
7
|
/**
|
|
7
8
|
* Command to create new view files
|
|
8
9
|
*/
|
|
9
|
-
declare class MakeViewCommand {
|
|
10
|
+
declare class MakeViewCommand extends Command {
|
|
10
11
|
/**
|
|
11
12
|
* Create a new view file
|
|
12
13
|
*
|
|
@@ -98,5 +99,4 @@ declare class ViewServiceProvider extends ServiceProvider {
|
|
|
98
99
|
boot(): Promise<void>;
|
|
99
100
|
}
|
|
100
101
|
//#endregion
|
|
101
|
-
export { EdgeViewEngine, MakeViewCommand, type ViewContract, EdgeViewEngine as ViewManager, ViewServiceProvider };
|
|
102
|
-
//# sourceMappingURL=index.d.ts.map
|
|
102
|
+
export { EdgeViewEngine, MakeViewCommand, type ViewContract, EdgeViewEngine as ViewManager, ViewServiceProvider };
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
23
|
//#endregion
|
|
24
24
|
let node_fs_promises = require("node:fs/promises");
|
|
25
25
|
node_fs_promises = __toESM(node_fs_promises);
|
|
26
|
+
let __h3ravel_musket = require("@h3ravel/musket");
|
|
27
|
+
__h3ravel_musket = __toESM(__h3ravel_musket);
|
|
26
28
|
let node_path = require("node:path");
|
|
27
29
|
node_path = __toESM(node_path);
|
|
28
30
|
let edge_js = require("edge.js");
|
|
@@ -34,7 +36,7 @@ __h3ravel_core = __toESM(__h3ravel_core);
|
|
|
34
36
|
/**
|
|
35
37
|
* Command to create new view files
|
|
36
38
|
*/
|
|
37
|
-
var MakeViewCommand = class {
|
|
39
|
+
var MakeViewCommand = class extends __h3ravel_musket.Command {
|
|
38
40
|
/**
|
|
39
41
|
* Create a new view file
|
|
40
42
|
*
|
|
@@ -154,5 +156,4 @@ var ViewServiceProvider = class extends __h3ravel_core.ServiceProvider {
|
|
|
154
156
|
exports.EdgeViewEngine = EdgeViewEngine;
|
|
155
157
|
exports.MakeViewCommand = MakeViewCommand;
|
|
156
158
|
exports.ViewManager = EdgeViewEngine;
|
|
157
|
-
exports.ViewServiceProvider = ViewServiceProvider;
|
|
158
|
-
//# sourceMappingURL=index.js.map
|
|
159
|
+
exports.ViewServiceProvider = ViewServiceProvider;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
2
|
+
import { Command } from "@h3ravel/musket";
|
|
2
3
|
import { dirname } from "node:path";
|
|
3
4
|
import { Edge } from "edge.js";
|
|
4
5
|
import { ServiceProvider } from "@h3ravel/core";
|
|
@@ -7,7 +8,7 @@ import { ServiceProvider } from "@h3ravel/core";
|
|
|
7
8
|
/**
|
|
8
9
|
* Command to create new view files
|
|
9
10
|
*/
|
|
10
|
-
var MakeViewCommand = class {
|
|
11
|
+
var MakeViewCommand = class extends Command {
|
|
11
12
|
/**
|
|
12
13
|
* Create a new view file
|
|
13
14
|
*
|
|
@@ -124,5 +125,4 @@ var ViewServiceProvider = class extends ServiceProvider {
|
|
|
124
125
|
};
|
|
125
126
|
|
|
126
127
|
//#endregion
|
|
127
|
-
export { EdgeViewEngine, MakeViewCommand, EdgeViewEngine as ViewManager, ViewServiceProvider };
|
|
128
|
-
//# sourceMappingURL=index.mjs.map
|
|
128
|
+
export { EdgeViewEngine, MakeViewCommand, EdgeViewEngine as ViewManager, ViewServiceProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/view",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "View rendering system for H3ravel framework",
|
|
5
5
|
"h3ravel": {
|
|
6
6
|
"providers": [
|
|
@@ -42,16 +42,17 @@
|
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://h3ravel.toneflix.net",
|
|
44
44
|
"dependencies": {
|
|
45
|
+
"@h3ravel/musket": "^0.1.10",
|
|
45
46
|
"edge.js": "^6.3.0",
|
|
46
|
-
"@h3ravel/http": "11.3.
|
|
47
|
-
"@h3ravel/core": "1.
|
|
47
|
+
"@h3ravel/http": "11.3.5",
|
|
48
|
+
"@h3ravel/core": "1.17.0"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
51
|
"typescript": "^5.0.0",
|
|
51
52
|
"vitest": "^2.0.0"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
|
-
"@h3ravel/shared": "0.22.
|
|
55
|
+
"@h3ravel/shared": "0.22.3"
|
|
55
56
|
},
|
|
56
57
|
"scripts": {
|
|
57
58
|
"dev": "tsx watch src/index.ts",
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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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QAAQ,QAAQ;GACpC,OAAO,QAAQ,IAAI,aAAa;GACjC,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/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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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