-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as compiler from "@marko/compiler"; | ||
|
||
export const compile = { | ||
async server(text, { path }) { | ||
return (await compiler.compile(text, path)).code; | ||
}, | ||
}; | ||
|
||
export const render = (component, props) => component.renderToString(props); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { filter } 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.config.location.server, directory); | ||
|
||
const { default : component } = await load(components.join(name)); | ||
|
||
return app.view({ body: render(component, props), ...options }); | ||
}; | ||
|
||
const name = "marko"; | ||
const dependencies = ["@marko/compiler", "@marko/translator-default"]; | ||
const default_extension = ".marko"; | ||
const on = filter(peers, ([key]) => dependencies.includes(key)); | ||
|
||
export default ({ extension = default_extension } = {}) => { | ||
const rootname = name; | ||
let imports = {}; | ||
|
||
return { | ||
name: `primate:${name}`, | ||
async init(app, next) { | ||
await depend(on, `frontend:${name}`); | ||
|
||
imports = await import("./imports.js"); | ||
|
||
return next(app); | ||
}, | ||
async register(app, next) { | ||
const { config } = app; | ||
|
||
app.register(extension, { | ||
handle: handler({ | ||
directory: config.location.components, | ||
render: imports.render, | ||
}), | ||
compile: { | ||
...await compile({ | ||
app, | ||
extension, | ||
rootname, | ||
compile: imports.compile, | ||
}), | ||
// no support for hydration | ||
client: _ => _, | ||
}, | ||
}); | ||
|
||
return next(app); | ||
}, | ||
}; | ||
}; | ||
|