@h3ravel/view 1.29.0-alpha.16 → 2.0.0-alpha.16
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/package.json +6 -8
- package/dist/index.cjs +0 -126
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/view",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.16",
|
|
4
4
|
"description": "View rendering system for H3ravel framework",
|
|
5
5
|
"h3ravel": {
|
|
6
6
|
"providers": [
|
|
@@ -8,8 +8,6 @@
|
|
|
8
8
|
]
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
-
"main": "./dist/index.cjs",
|
|
12
|
-
"module": "./dist/index.js",
|
|
13
11
|
"types": "./dist/index.d.ts",
|
|
14
12
|
"publishConfig": {
|
|
15
13
|
"access": "public"
|
|
@@ -44,8 +42,8 @@
|
|
|
44
42
|
"homepage": "https://h3ravel.toneflix.net",
|
|
45
43
|
"dependencies": {
|
|
46
44
|
"@h3ravel/musket": "^1.29.0-alpha.15",
|
|
47
|
-
"@h3ravel/core": "^
|
|
48
|
-
"@h3ravel/http": "^11.
|
|
45
|
+
"@h3ravel/core": "^2.0.0-alpha.16",
|
|
46
|
+
"@h3ravel/http": "^11.17.0-alpha.16",
|
|
49
47
|
"edge.js": "^6.3.0"
|
|
50
48
|
},
|
|
51
49
|
"devDependencies": {
|
|
@@ -53,11 +51,11 @@
|
|
|
53
51
|
"vitest": "^4.1.8"
|
|
54
52
|
},
|
|
55
53
|
"peerDependencies": {
|
|
56
|
-
"@h3ravel/shared": "^
|
|
57
|
-
"@h3ravel/support": "^
|
|
54
|
+
"@h3ravel/shared": "^2.0.0-alpha.16",
|
|
55
|
+
"@h3ravel/support": "^2.0.0-alpha.16"
|
|
58
56
|
},
|
|
59
57
|
"scripts": {
|
|
60
|
-
"dev": "
|
|
58
|
+
"dev": "tsdown --watch --config-loader unrun",
|
|
61
59
|
"typecheck": "tsc --noEmit",
|
|
62
60
|
"build": "tsdown --config-loader unrun",
|
|
63
61
|
"start": "node dist/index.js",
|
package/dist/index.cjs
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
let node_fs_promises = require("node:fs/promises");
|
|
3
|
-
let _h3ravel_musket = require("@h3ravel/musket");
|
|
4
|
-
let node_path = require("node:path");
|
|
5
|
-
let edge_js = require("edge.js");
|
|
6
|
-
let _h3ravel_http = require("@h3ravel/http");
|
|
7
|
-
let _h3ravel_support = require("@h3ravel/support");
|
|
8
|
-
//#region src/Commands/MakeViewCommand.ts
|
|
9
|
-
/**
|
|
10
|
-
* Command to create new view files
|
|
11
|
-
*/
|
|
12
|
-
var MakeViewCommand = class extends _h3ravel_musket.Command {
|
|
13
|
-
/**
|
|
14
|
-
* Create a new view file
|
|
15
|
-
*
|
|
16
|
-
* @param name - View name (can include directories like 'auth/login')
|
|
17
|
-
* @param options - Command options
|
|
18
|
-
*/
|
|
19
|
-
static async make(name, options = {}) {
|
|
20
|
-
const { force = false, basePath = "src/resources/views" } = options;
|
|
21
|
-
const path = `${basePath}/${name}.edge`;
|
|
22
|
-
if (name.includes("/")) await (0, node_fs_promises.mkdir)((0, node_path.dirname)(path), { recursive: true });
|
|
23
|
-
if (!force) try {
|
|
24
|
-
const { FileSystem } = await import("@h3ravel/shared");
|
|
25
|
-
if (await FileSystem.fileExists(path)) throw new Error(`View ${name} already exists`);
|
|
26
|
-
} catch (error) {
|
|
27
|
-
if (error instanceof Error && error.message.includes("already exists")) throw error;
|
|
28
|
-
}
|
|
29
|
-
await (0, node_fs_promises.writeFile)(path, `{{-- ${path} --}}
|
|
30
|
-
<div>
|
|
31
|
-
<!-- Your view content here -->
|
|
32
|
-
<h1>{{ title ?? 'Welcome' }}</h1>
|
|
33
|
-
</div>`);
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
//#endregion
|
|
37
|
-
//#region src/EdgeViewEngine.ts
|
|
38
|
-
/**
|
|
39
|
-
* Edge.js implementation of the ViewContract
|
|
40
|
-
*/
|
|
41
|
-
var EdgeViewEngine = class {
|
|
42
|
-
edge;
|
|
43
|
-
constructor(options = {}) {
|
|
44
|
-
this.edge = edge_js.Edge.create({ cache: options.cache ?? false });
|
|
45
|
-
if (options.viewsPath) this.edge.mount(options.viewsPath);
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Render a template with the given data
|
|
49
|
-
*/
|
|
50
|
-
async render(template, data = {}) {
|
|
51
|
-
return await this.edge.render(template, data);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Check if a template exists
|
|
55
|
-
*/
|
|
56
|
-
exists(_template) {
|
|
57
|
-
try {
|
|
58
|
-
return true;
|
|
59
|
-
} catch {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Mount a directory for template lookup
|
|
65
|
-
*/
|
|
66
|
-
mount(path) {
|
|
67
|
-
this.edge.mount(path);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Register a global variable/helper
|
|
71
|
-
*/
|
|
72
|
-
global(key, value) {
|
|
73
|
-
this.edge.global(key, value);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Get the underlying Edge instance
|
|
77
|
-
*/
|
|
78
|
-
getEdge() {
|
|
79
|
-
return this.edge;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
//#endregion
|
|
83
|
-
//#region src/Providers/ViewServiceProvider.ts
|
|
84
|
-
/**
|
|
85
|
-
* View Service Provider
|
|
86
|
-
*
|
|
87
|
-
* Registers the view engine with the application container
|
|
88
|
-
*/
|
|
89
|
-
var ViewServiceProvider = class extends _h3ravel_support.ServiceProvider {
|
|
90
|
-
static priority = 995;
|
|
91
|
-
async register() {
|
|
92
|
-
const edge = new EdgeViewEngine({
|
|
93
|
-
viewsPath: this.app.getPath("views"),
|
|
94
|
-
cache: process.env.NODE_ENV === "production"
|
|
95
|
-
}).getEdge();
|
|
96
|
-
/**
|
|
97
|
-
* Bind the view engine to the container
|
|
98
|
-
*/
|
|
99
|
-
this.app.bind("edge", () => edge);
|
|
100
|
-
}
|
|
101
|
-
async boot() {
|
|
102
|
-
/**
|
|
103
|
-
* Initialize the view handler method
|
|
104
|
-
*
|
|
105
|
-
* @param template
|
|
106
|
-
* @param params
|
|
107
|
-
* @returns
|
|
108
|
-
*/
|
|
109
|
-
const view = async (template, data) => {
|
|
110
|
-
let response = this.app.make("http.response");
|
|
111
|
-
const request = this.app.make("http.request");
|
|
112
|
-
if (response instanceof _h3ravel_http.Responsable) response = response.toResponse(request);
|
|
113
|
-
return response.html(await this.app.make("edge").render(template, data), true);
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Dynamically bind the view renderer to the service container.
|
|
117
|
-
* This allows any part of the request lifecycle to render templates using Edge.
|
|
118
|
-
*/
|
|
119
|
-
this.app.bind("view", () => view);
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
//#endregion
|
|
123
|
-
exports.EdgeViewEngine = EdgeViewEngine;
|
|
124
|
-
exports.MakeViewCommand = MakeViewCommand;
|
|
125
|
-
exports.ViewManager = EdgeViewEngine;
|
|
126
|
-
exports.ViewServiceProvider = ViewServiceProvider;
|