got parser to work (mostly i think). it aint so pretty tho. ALSO BRO FUCKING CRLF

This commit is contained in:
kree 2026-08-14 03:17:52 -04:00
parent 43779e110a
commit cd07c310cb
7 changed files with 258 additions and 127 deletions

View file

@ -1,26 +1,15 @@
import { describe, it, expect } from 'bun:test'
import { Gin } from '../../src/util/gin'
import { describe, it, expect, beforeAll } from 'bun:test'
import { Engine } from '../../src/util/gin'
describe('Gin template porting test', () => {
it('parse', async () => {
const example =
`Dear {{.Name}},
{{if .Attended}}
It was a pleasure to see you at the wedding.
{{- else}}
It is a shame you couldn't make it to the wedding.
{{- end}}
{{with .Gift -}}
Thank you for the lovely {{.}}.
{{end}}
Best wishes,
Josie`;
const e = new Engine();
const template = {
name: 'example',
root: Gin.parse(example)
};
beforeAll(async () => {
await e.LoadHTMLGlob('examples/*html');
e.printTemplates();
})
it('data', async () => {
const data = [
{
Name: 'Aunt Mildred',
@ -40,40 +29,31 @@ Josie`;
]
const expected =
`Dear Aunt Mildred,
`Dear Aunt Mildred,
It was a pleasure to see you at the wedding.
Thank you for the lovely bone china tea set.
Best wishes,
Josie
Dear Uncle John,
It is a shame you couldn't make it to the wedding.
Thank you for the lovely moleskin pants.
Best wishes,
Josie
Dear Cousin Rodney,
It is a shame you couldn't make it to the wedding.
Best wishes,
Josie`
const actual = data.map(r => Gin.execute(template, r)).join('\n\n');
console.debug(Gin.execute(template, data[0]))
const actual = data.map(d => e.HTML("examples/data.html", d)).join('\n');
expect(actual).toEqual(expected);
})
// it('parseGlob', async () => {
// const gin = new Gin();
// const paths = await gin.parseGlob('public/**/*html');
// })
// it('parseHTML', async () => {
// const gin = new Gin();
// const text = await gin.parseHTML('public/pages/movie.html');
// console.log(text);
// })
it('define', async () => {
expect(e.HTML("T1", {})).toEqual('ONE')
expect(e.HTML("T2", {})).toEqual('TWO')
expect(e.HTML("T3", {})).toEqual('ONE TWO')
})
})