Found out that the templates generated by lodash (and all template engines) don't connect back to the original template file so you lose line numbers. Not sure how to solve it.

main
Zed A. Shaw 3 months ago
parent 44f7603ddc
commit 7284e510d8
  1. 33
      bin/app.js
  2. 25
      templates/todo.html

@ -3,29 +3,36 @@ import FastifyStatic from "@fastify/static";
import path from "path";
import { ToDo } from "../lib/models.js";
import fs from "fs";
import _ from "lodash";
import template from "lodash/template.js";
const fastify = Fastify({
logger: true
});
fastify.get("/todo", async (request, reply) => {
const list = await ToDo.all({});
fastify.get("/todo", async (req, rep) => {
try {
const todo_list = await ToDo.all({});
return list;
});
// this is for exporing the problem of getting good error messages from templates
const tmpl_src = fs.readFileSync("templates/todo.html");
const tmpl = template(tmpl_src, {sourceURL: "templates/todo.html"});
fastify.get("/todo.html", async (req, rep) => {
const list = await ToDo.all({});
console.log("FUNCTION-----\n", tmpl.toString());
const tmpl_src = fs.readFileSync("templates/todo.html");
const tmpl = _.template(tmpl_src, );
const result = tmpl({todo_list});
const result = tmpl({message: "Hello!"});
rep.code(200)
.type("text/html")
.send(result);
} catch(error) {
console.error(error);
console.error(error.stack);
console.error(error.source);
}
});
fastify.get("/todo.html", async (req, rep) => {
rep.code(200)
.type("text/html")
.send(result);
});
fastify.register(FastifyStatic, {

@ -3,27 +3,24 @@
<html>
<head>
<script src="/alpine.js"></script>
<script src="/fsm.js"></script>
<title>Bandolier2</title>
<style>
@import "/open-props.min.css";
@import "/normalize.min.css";
</style>
blockquote {
--_accent-1: var(--lime-5);
--_accent-2: var(--lime-4);
--_bg: var(--surface-2);
--_ink: var(--text-1);
<head>
</head>
color: var(--_ink);
border-color: var(--_accent-2);
background-color: var(--_bg);
justify-self: flex-start;
}
</style>
<head>
<body>
<h1><%= message %></h1>
<h1><%= your_todos %></h1>
<p>This is a template!</p>
<ol>
<% for(let todo of todo_list) { %>
<li><%= todo.task %></li>
<% } %>
</ol>
</body>
</html>

Loading…
Cancel
Save