This commit is contained in:
2025-11-27 20:05:56 +01:00
parent 63ad5e807b
commit 6abd4b0373
5 changed files with 92 additions and 7 deletions

View File

@@ -19,9 +19,8 @@ def littlejs_href(example, protocol, domain):
if is_project:
return f"{protocol}://{domain}/examples/{file}/"
# Short examples: internal wrapper
return f"{protocol}://{domain}/examples/shorts/base.html?file={file}"
# Non-full shorts: use custom runner without example browser overhead
return f"{protocol}://{domain}/examples/shorts/run.html?file={file}"
class FilterModule(object):
def filters(self):

View File

@@ -17,6 +17,15 @@
- docker compose build
- docker compose up
- name: "Render LittleJS run.html for shorts"
template:
src: "html/run.html.j2"
dest: "{{ LITTLEJS_RUN_HOST_ABS }}"
mode: "0644"
notify:
- docker compose build
- docker compose up
- name: "flush docker compose for '{{ application_id }}'"
meta: flush_handlers

View File

@@ -1,4 +1,3 @@
# roles/web-app-littlejs/templates/Dockerfile.j2
FROM nginx:alpine
# Static LittleJS assets engine builds + examples
@@ -7,3 +6,6 @@ COPY ./{{ LITTLEJS_APP_REL }}/dist /usr/share/nginx/html/dist
# Custom Infinito.Nexus landing page with Bootstrap menu and tiles
COPY ./{{ LITTLEJS_INDEX_HOST_REL }} /usr/share/nginx/html/index.html
# Custom runner for non-full LittleJS shorts examples
COPY ./{{ LITTLEJS_RUN_HOST_REL }} /usr/share/nginx/html/examples/shorts/run.html

View File

@@ -0,0 +1,69 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>LittleJS Example</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- LittleJS engine bundle -->
<script src="../../dist/littlejs.js"></script>
<script>
(function () {
// Read ?file=... from query string
const params = new URLSearchParams(window.location.search);
let file = params.get("file") || "helloWorld.js";
// Basic safety: keep file in current directory and avoid traversal
if (file.includes("/") || file.includes("\\")) {
console.warn("Invalid file parameter, falling back to default");
file = "helloWorld.js";
}
if (!file.endsWith(".js")) {
file = file + ".js";
}
// Dynamically load the selected example script from /examples/shorts/
const script = document.createElement("script");
script.src = file;
script.onload = () => {
console.log("Loaded LittleJS example:", file);
if (typeof window.engineInit !== "function") {
console.error("LittleJS engineInit not found");
return;
}
// Fallbacks if some callbacks are not defined by the example
const gameInit = window.gameInit || function(){};
const gameUpdate = window.gameUpdate || function(){};
const gameUpdatePost = window.gameUpdatePost || function(){};
const gameRender = window.gameRender || function(){};
const gameRenderPost = window.gameRenderPost || function(){};
// Start LittleJS engine similar to the Example Browser
Promise.resolve(
window.engineInit(
gameInit,
gameUpdate,
gameUpdatePost,
gameRender,
gameRenderPost,
['tiles.png?' + Date.now()]
)
).catch((error) => {
console.error("Error starting LittleJS engine:", error);
});
};
script.onerror = () => {
console.error("Failed to load LittleJS example:", file);
};
document.body.appendChild(script);
})();
</script>
</body>

View File

@@ -1,7 +1,7 @@
# General
application_id: "web-app-littlejs"
entity_name: "{{ application_id | get_entity_name }}"
domain: "{{ domains | get_domain(application_id) }}"
application_id: "web-app-littlejs"
entity_name: "{{ application_id | get_entity_name }}"
domain: "{{ domains | get_domain(application_id) }}"
LITTLEJS_HEADLINE: "LittleJS Playground"
@@ -23,3 +23,9 @@ LITTLEJS_INDEX_HOST_REL: "volumes/index.html"
# Helper variables
LITTLEJS_CONTAINER: "{{ entity_name }}"
LITTLEJS_SERVICE: "{{ entity_name }}"
# Runner HTML for non-full examples
LITTLEJS_RUN_HOST_ABS: "{{ [ docker_compose.directories.volumes, 'run.html' ] | path_join }}"
LITTLEJS_RUN_HOST_REL: "volumes/run.html"