Skip to content

Commit

Permalink
add eta support (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Jun 7, 2024
1 parent 17786c0 commit cfcbda4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@marko/compiler": "5",
"@marko/translator-default": "6",
"babel-preset-solid": "1",
"eta": "3",
"handlebars": "4",
"htmx-esm": "0.2",
"marked": "12",
Expand Down Expand Up @@ -66,6 +67,9 @@
"babel-preset-solid": {
"optional": true
},
"eta": {
"optional": true
},
"handlebars": {
"optional": true
},
Expand Down
17 changes: 17 additions & 0 deletions packages/frontend/src/frontends/eta/imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Eta } from "eta";
const eta = new Eta();

export const compile = {
server(text) {
return `
import { Eta } from "eta";
const eta = new Eta();
${eta.compile(text).toString()}
export default (props, options) => anonymous.call(eta, props, options);
`;
},
};

export const render = (component, props) => component(props);
49 changes: 49 additions & 0 deletions packages/frontend/src/frontends/eta/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as O from "rcompat/object";
import { compile, peers, load } from "../common/exports.js";
import depend from "../depend.js";

const handler = ({ directory, render }) => (name, props = {}, options = {}) =>
async app => {
const components = app.runpath(app.get("location.server"), directory);
const { default : component } = await load(components.join(name));

return app.view({ body: render(component, props), ...options });
};

const name = "eta";
const dependencies = ["eta"];
const default_extension = ".eta";
const on = O.filter(peers, ([key]) => dependencies.includes(key));

export default ({ extension = default_extension } = {}) => {
const rootname = name;

return {
name: `primate:${name}`,
async init(app, next) {
await depend(on, `frontend:${name}`);

const imports = await import("./imports.js");

app.register(extension, {
handle: handler({
directory: app.get("location.components"),
render: imports.render,
}),
compile: {
...await compile({
app,
extension,
rootname,
compile: imports.compile,
}),
// no support for hydration
client: _ => _,
},
});

return next(app);
},
};
};

9 changes: 5 additions & 4 deletions packages/frontend/src/frontends/exports.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
export { default as webc } from "./webc/module.js";
export { default as angular } from "./angular/module.js";
export { default as eta } from "./eta/module.js";
export { default as handlebars } from "./handlebars/module.js";
export { default as htmx } from "./htmx/module.js";
export { default as markdown } from "./markdown/module.js";
export { default as marko } from "./marko/module.js";
export { default as react } from "./react/module.js";
export { default as solid } from "./solid/module.js";
export { default as svelte } from "./svelte/module.js";
export { default as vue } from "./vue/module.js";
export { default as angular } from "./angular/module.js";
export { default as handlebars } from "./handlebars/module.js";
export { default as marko } from "./marko/module.js";
export { default as webc } from "./webc/module.js";

0 comments on commit cfcbda4

Please sign in to comment.