Skip to content

Commit

Permalink
frontend/html: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Mar 9, 2024
1 parent 655fc13 commit a77cdf6
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions packages/frontend/src/frontends/htmx/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ const handle = (name, props, options = {}) => async (app, _, request) => {
})(app, _, request);
};

const htmx = "htmx-esm";
const templates = "client-side-templates";

const base_import_template = (name, app) =>
app.build.export(`export * from "htmx-esm/client-side-templates/${name}";`);
app.build.export(`export * from "${htmx}/${templates}/${name}";`);

const import_template = {
handlebars: app => base_import_template("handlebars", app),
Expand All @@ -45,23 +48,19 @@ export default ({
return next(app);
},
async register(app, next) {
app.build.export("export { default as htmx } from \"htmx-esm\";");
app.build.export(`export { default as htmx } from "${htmx}";`);
app.register(extension, { handle });

for (const name of extensions) {
app.build.export(`export * from "htmx-esm/${name}";`);
}
extensions.forEach(extension_name =>
app.build.export(`export * from "${htmx}/${extension_name}";`));

if (Object.keys(client_side_templates).length > 0) {
const base = "client-side-templates";
const templates = client_side_templates.join(", ");

if (!extensions.includes(base)) {
errors.MissingClientSideTemplateDependency.throw(base, templates);
}
for (const template of client_side_templates) {
await import_template[template](app);
if (!extensions.includes(templates)) {
errors.MissingClientSideTemplateDependency.throw(templates,
client_side_templates.join(", "));
}
client_side_templates.forEach(client_side_template =>
import_template[client_side_template](app));
}

return next(app);
Expand Down

0 comments on commit a77cdf6

Please sign in to comment.