@mojojs/core 0.15.0 → 0.15.1
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/lib/cli/create-full-app.js +5 -5
- package/lib/cli/create-lite-app.js +4 -4
- package/lib/core.d.ts +1 -1
- package/lib/plugins/view-helpers.js +10 -0
- package/lib/plugins/view-helpers.js.map +1 -1
- package/package.json +1 -1
- package/vendor/README.md +1 -1
- package/vendor/views/mojo/debug.html.mt +51 -51
|
@@ -53,18 +53,18 @@ const jsController = `export default class Controller {
|
|
|
53
53
|
const mtLayout = `<!DOCTYPE html>
|
|
54
54
|
<html>
|
|
55
55
|
<head>
|
|
56
|
-
|
|
56
|
+
<%%= ctx.mojoFaviconTag() %>
|
|
57
57
|
<title>Welcome</title>
|
|
58
58
|
</head>
|
|
59
|
-
<body
|
|
59
|
+
<body><%%== view.content %></body>
|
|
60
60
|
</html>
|
|
61
61
|
`;
|
|
62
|
-
const mtView = `<%% view.layout = 'default';
|
|
62
|
+
const mtView = `<%% view.layout = 'default'; %>
|
|
63
63
|
<h2><%%= msg %></h2>
|
|
64
64
|
<p>
|
|
65
65
|
This page was generated from the template "views/example/welcome.html.mt" and the layout
|
|
66
|
-
"views/layouts/default.html.mt", <a href="<%%= ctx.urlFor()
|
|
67
|
-
<a href="<%%= ctx.urlFor('/public/index.html')
|
|
66
|
+
"views/layouts/default.html.mt", <a href="<%%= ctx.urlFor() %>">click here</a> to reload the page or
|
|
67
|
+
<a href="<%%= ctx.urlFor('/public/index.html') %>">here</a> to move forward to a static page.
|
|
68
68
|
</p>
|
|
69
69
|
`;
|
|
70
70
|
const staticFile = `<!DOCTYPE html>
|
|
@@ -38,7 +38,7 @@ app.start();
|
|
|
38
38
|
const indexTemplate = \`
|
|
39
39
|
<h1>Waiting...</h1>
|
|
40
40
|
<script>
|
|
41
|
-
const ws = new WebSocket('<%%= ctx.urlFor('heading')
|
|
41
|
+
const ws = new WebSocket('<%%= ctx.urlFor('heading') %>');
|
|
42
42
|
ws.onmessage = event => { document.querySelector('h1').innerHTML = event.data };
|
|
43
43
|
</script>
|
|
44
44
|
\`;
|
|
@@ -47,10 +47,10 @@ const defaultLayout = \`
|
|
|
47
47
|
<!DOCTYPE html>
|
|
48
48
|
<html>
|
|
49
49
|
<head>
|
|
50
|
-
|
|
51
|
-
<title><%%= title
|
|
50
|
+
<%%= ctx.mojoFaviconTag() %>
|
|
51
|
+
<title><%%= title %></title>
|
|
52
52
|
</head>
|
|
53
|
-
<body
|
|
53
|
+
<body><%%== view.content %></body>
|
|
54
54
|
</html>
|
|
55
55
|
\`;
|
|
56
56
|
`;
|
package/lib/core.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { inspect } from 'util';
|
|
2
2
|
import DOM, { SafeString } from '@mojojs/dom';
|
|
3
3
|
export default function viewHelpersPlugin(app) {
|
|
4
|
+
app.addHelper('currentRoute', currentRoute);
|
|
4
5
|
app.decorateContext('inspect', (object, options) => inspect(object, options));
|
|
5
6
|
app.addHelper('include', include);
|
|
6
7
|
app.addHelper('mojoFaviconTag', mojoFaviconTag);
|
|
@@ -8,6 +9,15 @@ export default function viewHelpersPlugin(app) {
|
|
|
8
9
|
app.addHelper('styleTag', styleTag);
|
|
9
10
|
app.addHelper('tag', tag);
|
|
10
11
|
}
|
|
12
|
+
function currentRoute(ctx) {
|
|
13
|
+
const plan = ctx.plan;
|
|
14
|
+
if (plan === null)
|
|
15
|
+
return null;
|
|
16
|
+
const endpoint = plan.endpoint;
|
|
17
|
+
if (endpoint === undefined)
|
|
18
|
+
return null;
|
|
19
|
+
return endpoint.customName ?? endpoint.defaultName ?? null;
|
|
20
|
+
}
|
|
11
21
|
async function include(ctx, options, stash) {
|
|
12
22
|
return await ctx.renderToString(options, stash);
|
|
13
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-helpers.js","sourceRoot":"","sources":["../../src/plugins/view-helpers.ts"],"names":[],"mappings":"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IAAI,CAAC,QAAQ,CAAC;IAC/B,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACxC,OAAO,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,WAAW,IAAI,IAAI,CAAC;AAC7D,CAAC;AAED,KAAK,UAAU,OAAO,CAAC,GAAgB,EAAE,OAAsB,EAAE,KAA0B;IACzF,OAAO,MAAM,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,cAAc,CAAC,GAAgB;IACtC,OAAO,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,EAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,mBAAmB,CAAC,EAAC,CAAC,CAAC;AACnF,CAAC;AAED,SAAS,SAAS,CAAC,GAAgB,EAAE,MAAc;IACjD,OAAO,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAC,GAAG,EAAE,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAC,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,QAAQ,CAAC,GAAgB,EAAE,MAAc;IAChD,OAAO,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,EAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,EAAC,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,GAAG,CACV,GAAgB,EAChB,IAAY,EACZ,QAAgC,EAAE,EAClC,UAA+B,EAAE;IAEjC,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;AACrE,CAAC"}
|
package/package.json
CHANGED
package/vendor/README.md
CHANGED
|
@@ -4,7 +4,7 @@ This distribution includes a few files with different licenses that have been bu
|
|
|
4
4
|
|
|
5
5
|
* Mojolicious Artwork
|
|
6
6
|
|
|
7
|
-
Copyright (C) 2010-
|
|
7
|
+
Copyright (C) 2010-2022, Sebastian Riedel.
|
|
8
8
|
|
|
9
9
|
Licensed under the [CC-SA License, Version 4.0](http://creativecommons.org/licenses/by-sa/4.0).
|
|
10
10
|
|
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
<html>
|
|
4
4
|
<head>
|
|
5
5
|
<title>Debug</title>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
%= ctx.mojoFaviconTag()
|
|
7
|
+
%= ctx.scriptTag('/mojo/bootstrap/bootstrap.bundle.min.js')
|
|
8
|
+
%= ctx.scriptTag('/mojo/highlight.js/highlight.pack.js')
|
|
9
|
+
%= ctx.styleTag('/mojo/bootstrap/bootstrap.min.css')
|
|
10
|
+
%= ctx.styleTag('/mojo/highlight.js/highlight-mojo-dark.css')
|
|
11
|
+
%= ctx.styleTag('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css')
|
|
12
|
+
%= ctx.styleTag('/mojo/mojo.css')
|
|
13
13
|
<script>
|
|
14
14
|
hljs.initHighlightingOnLoad();
|
|
15
15
|
window.onload = function() {
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
<div class="row flex-wrap">
|
|
62
62
|
<main class="col-sm-12 col-md-8 col-lg-10 py-md-3 pl-md-5">
|
|
63
63
|
<div class="row mojo-divider">
|
|
64
|
-
|
|
64
|
+
% if (ctx.stash.exception !== undefined) {
|
|
65
65
|
<div class="alert alert-danger mojo-wide" role="alert">
|
|
66
66
|
<h2>Server Error</h2>
|
|
67
67
|
This application is in <b>development</b> mode and will show internal information to help you with
|
|
@@ -69,33 +69,33 @@
|
|
|
69
69
|
</div>
|
|
70
70
|
<div id="showcase" class="mojo-box mojo-code mojo-no-bottom-border mojo-no-top-border mojo-border-radius-top">
|
|
71
71
|
<pre id="error" class="mojo-error"><%= exception %></pre>
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
% const context = await view.exceptionContext(exception);
|
|
73
|
+
% if (context !== null) {
|
|
74
74
|
<div>
|
|
75
75
|
<table class="mojo-wide">
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
% for (const line of context.source) {
|
|
77
|
+
% const extra = context.line === line.num ? ' mojo-important' : '';
|
|
78
78
|
<tr>
|
|
79
79
|
<td class="text-right<%= extra %>"><%= line.num %></td>
|
|
80
80
|
<td class="mojo-context mojo-wide<%= extra %>"><pre><code><%= line.code %></code></pre></td>
|
|
81
81
|
</tr>
|
|
82
|
-
|
|
82
|
+
% }
|
|
83
83
|
</table>
|
|
84
84
|
</div>
|
|
85
|
-
|
|
85
|
+
% }
|
|
86
86
|
</div>
|
|
87
87
|
<div id="trace" class="mojo-box mojo-no-padding more mojo-no-top-border mojo-border-radius-bottom">
|
|
88
88
|
<div id="frames" class="more">
|
|
89
89
|
<table class="mojo-striped-grey mojo-wide">
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
% const lines = exception.stack.split('\n').filter(line => line.match(/^\s*at\ /));
|
|
91
|
+
% const trace = lines.map(val => val.replace(/^\s+/, ''));
|
|
92
|
+
% for (const frame of trace) {
|
|
93
93
|
<tr><td class="mojo-value"><pre><%= frame %></pre></td></tr>
|
|
94
|
-
|
|
94
|
+
% }
|
|
95
95
|
</table>
|
|
96
96
|
</div>
|
|
97
97
|
</div>
|
|
98
|
-
|
|
98
|
+
% } else {
|
|
99
99
|
<div class="alert alert-warning mojo-wide" role="alert">
|
|
100
100
|
<h2>Page Not Found</h2>
|
|
101
101
|
This application is in <b>development</b> mode and will show internal information to help you with
|
|
@@ -108,12 +108,12 @@
|
|
|
108
108
|
for <code><%= ctx.req.path %></code>, maybe you need to add a new one?
|
|
109
109
|
</p>
|
|
110
110
|
</div>
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
% function walk (route, depth) {
|
|
112
|
+
% const pattern = route.pattern;
|
|
113
|
+
% let unparsed = pattern.unparsed || '/';
|
|
114
|
+
% if (depth > 0) unparsed = `+${unparsed}`;
|
|
115
|
+
% pattern.match('/', {isEndpoint: route.isEndpoint});
|
|
116
|
+
% const regex = pattern.regex.toString();
|
|
117
117
|
<tr data-bs-toggle="tooltip" data-bs-placement="left" data-bs-html="true"
|
|
118
118
|
title="<b>Regex:</b> <code><%= regex %></code>">
|
|
119
119
|
<td class="mojo-value">
|
|
@@ -123,17 +123,17 @@
|
|
|
123
123
|
<pre><%= route.methods.join(', ').toUpperCase() || '*' %></pre>
|
|
124
124
|
</td>
|
|
125
125
|
<td class="mojo-value">
|
|
126
|
-
|
|
126
|
+
% if (route.customName !== undefined) {
|
|
127
127
|
<span class="badge bg-success"><%= route.customName %></span>
|
|
128
|
-
|
|
128
|
+
% } else if (route.defaultName !== undefined) {
|
|
129
129
|
<span class="badge bg-secondary"><%= route.defaultName %></span>
|
|
130
|
-
|
|
130
|
+
% }
|
|
131
131
|
</td>
|
|
132
132
|
</tr>
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
% depth++;
|
|
134
|
+
%= route.children.map(child => walk(child, depth)).join('')
|
|
135
|
+
% depth--;
|
|
136
|
+
% }
|
|
137
137
|
<table class="mojo-striped-light mojo-wide">
|
|
138
138
|
<thead>
|
|
139
139
|
<tr>
|
|
@@ -142,43 +142,43 @@
|
|
|
142
142
|
<th>Name</th>
|
|
143
143
|
</tr>
|
|
144
144
|
</thead>
|
|
145
|
-
|
|
145
|
+
%= ctx.app.router.children.map(child => walk(child, 0)).join('')
|
|
146
146
|
</table>
|
|
147
147
|
</div>
|
|
148
|
-
|
|
148
|
+
% }
|
|
149
149
|
</div>
|
|
150
150
|
<div class="row mojo-divider">
|
|
151
151
|
<div id="request" class="mojo-box mojo-no-padding mojo-border-radius-both">
|
|
152
|
-
|
|
152
|
+
% function keyValue (key, value) {
|
|
153
153
|
<tr>
|
|
154
154
|
<td class="mojo-key text-right"><%= key %>:</td>
|
|
155
155
|
<td class="mojo-value"><pre><%= value %></pre></td>
|
|
156
156
|
</tr>
|
|
157
|
-
|
|
157
|
+
% }
|
|
158
158
|
<table class="mojo-striped mojo-fixed-table mojo-wide">
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
159
|
+
%= keyValue('Request ID', ctx.req.requestId)
|
|
160
|
+
%= keyValue('Method', ctx.req.method)
|
|
161
|
+
%= keyValue('Path', ctx.req.path)
|
|
162
|
+
%= keyValue('Base URL', ctx.req.baseUrl)
|
|
163
|
+
%= keyValue('Parameters', ctx.inspect((await ctx.params()).toObject()))
|
|
164
|
+
%= keyValue('Stash', ctx.inspect(ctx.stash) )
|
|
165
|
+
% const rawHeaders = ctx.req.raw.rawHeaders;
|
|
166
|
+
% for (let i = 0; i < rawHeaders.length; i += 2) {
|
|
167
|
+
%= keyValue(rawHeaders[i], rawHeaders[i + 1])
|
|
168
|
+
% }
|
|
169
169
|
</table>
|
|
170
170
|
</div>
|
|
171
171
|
</div>
|
|
172
172
|
<div class="row">
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
% if (ctx.app.log.history.length > 0) {
|
|
174
|
+
% const log = ctx.app.log.history.map(view.stringFormatter).join('');
|
|
175
175
|
<pre class="mojo-terminal"><code class="nohighlight"><%= log %></code></pre>
|
|
176
|
-
|
|
176
|
+
% } else {
|
|
177
177
|
<div class="alert alert-warning mojo-wide" role="alert">
|
|
178
178
|
The application log appears to be empty, perhaps the log level <b><%= ctx.app.log.level %></b> is too
|
|
179
179
|
high? Try lowering it to <b>trace</b> for framework specific information.
|
|
180
180
|
</div>
|
|
181
|
-
|
|
181
|
+
% }
|
|
182
182
|
</div>
|
|
183
183
|
</main>
|
|
184
184
|
</div>
|
|
@@ -190,7 +190,7 @@
|
|
|
190
190
|
<b>Free</b> and <b>Open Source</b>.
|
|
191
191
|
</div>
|
|
192
192
|
<div class="col-sm align-self-center text-center mojo-copy">
|
|
193
|
-
<i class="far fa-copyright"></i> 2021 Sebastian Riedel and the
|
|
193
|
+
<i class="far fa-copyright"></i> 2021-2022 Sebastian Riedel and the
|
|
194
194
|
<a href="https://github.com/mojolicious/mojo.js/AUTHORS">mojo.js contributors</a>.
|
|
195
195
|
</div>
|
|
196
196
|
<div class="col-sm align-self-center text-center mojo-social">
|