federalies / templast

a unist compliant syntax tree for template languages
MIT License
4 stars 0 forks source link

Virtual DOM approach. #1

Open ericdmoore opened 4 years ago

ericdmoore commented 4 years ago

Run the template string as through the rehype parser. And then do some post processing to merge it in with the templast system.

loganpowell commented 4 years ago

So happy to have found this! Are there some examples available (specifically for the hyperscript/virtual dom approach)?

ericdmoore commented 4 years ago

sadly I had to put development of this project on hold for the time being...but yeah the idea here is that it would be nice to have an adapter framework to turn a handlebars tempalte into a preact/hyperapp/ etc template.

where import hbs template and export toHyperapp likely uses the h function from hyperapp or preact etc. under the hood.

I'd love to hear other uses cases you might have - to help me make the case that i should switch back to this project sooner than not.

loganpowell commented 4 years ago

sadly I had to put development of this project on hold for the time being

I got this feeling when I started looking through the repo for code ;)

I can't say I have a strong need for this, so don't let it influence you, but I was trying to find something that would allow me to create templates with markdown, effectively creating functions like you have doc'd here:

(data) => h('h3', attrs.h3, data.title )

from something like this (file.md)

### {{ title }}

then I could use it by injecting data into the unified process like:

const file = fs.readFileSync("./file.md", { encoding: "utf8" })
const data = { title: "hello" }
const toH = require("hast-to-hyperscript")
...
unified()...use(templast({ data, impl: toH })).processSync(file)

Not sure how useful this would be to anyone but me though 😄