mirror of
https://github.com/facundoolano/jorge.git
synced 2024-12-26 21:58:51 +01:00
add liquid template support
This commit is contained in:
parent
73bbaa2c50
commit
c4486f5a07
4 changed files with 59 additions and 2 deletions
4
go.mod
4
go.mod
|
@ -4,6 +4,10 @@ go 1.22.0
|
|||
|
||||
require (
|
||||
github.com/niklasfasching/go-org v1.7.0 // indirect
|
||||
github.com/osteele/liquid v1.3.2 // indirect
|
||||
github.com/osteele/tuesday v1.0.3 // indirect
|
||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b // indirect
|
||||
gopkg.in/osteele/liquid.v1 v1.2.4 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
8
go.sum
8
go.sum
|
@ -1,5 +1,9 @@
|
|||
github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMimOjGMek=
|
||||
github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o=
|
||||
github.com/osteele/liquid v1.3.2 h1:G+MvVYt1HX2xuv99JgdrhV7zRVdlvFnNi8M5rN8gQmI=
|
||||
github.com/osteele/liquid v1.3.2/go.mod h1:VmzQQHa5v4E0GvGzqccfAfLgMwRk2V+s1QbxYx9dGak=
|
||||
github.com/osteele/tuesday v1.0.3 h1:SrCmo6sWwSgnvs1bivmXLvD7Ko9+aJvvkmDjB5G4FTU=
|
||||
github.com/osteele/tuesday v1.0.3/go.mod h1:pREKpE+L03UFuR+hiznj3q7j3qB1rUZ4XfKejwWFF2M=
|
||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
|
||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
@ -7,5 +11,9 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
|
|||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/osteele/liquid.v1 v1.2.4 h1:OioNeCaVyWL1jRXzRqQ2vr4ISBbTgtnYsJeVlToLhBw=
|
||||
gopkg.in/osteele/liquid.v1 v1.2.4/go.mod h1:9Bx5f04tf9SVwv3Tcx93dx3WH0EKWmE0Gjd6Dyoc5cs=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/niklasfasching/go-org/org"
|
||||
"gopkg.in/osteele/liquid.v1"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
@ -96,7 +97,13 @@ func (templ Template) Render() ([]byte, error) {
|
|||
}
|
||||
|
||||
} else {
|
||||
// TODO for other file types, assume a liquid template
|
||||
// for other file types, assume a liquid template
|
||||
engine := liquid.NewEngine()
|
||||
out, err := engine.ParseAndRenderString(string(contents), templ.Metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
contents = []byte(out)
|
||||
}
|
||||
|
||||
// TODO: if layout in metadata, pass the result to the rendered parent
|
||||
|
|
|
@ -89,13 +89,51 @@ tags: ["software", "web"]
|
|||
}
|
||||
|
||||
func TestRenderLiquid(t *testing.T) {
|
||||
// TODO
|
||||
input := `---
|
||||
title: my new post
|
||||
subtitle: a blog post
|
||||
tags: ["software", "web"]
|
||||
---
|
||||
<h1>{{ title }}</h1>
|
||||
<h2>{{ subtitle }}</h2>
|
||||
<ul>{% for tag in tags %}
|
||||
<li>{{tag}}</li>{% endfor %}
|
||||
</ul>
|
||||
`
|
||||
|
||||
file := newFile("test*.html", input)
|
||||
defer os.Remove(file.Name())
|
||||
|
||||
templ, err := Parse(file.Name())
|
||||
assertEqual(t, err, nil)
|
||||
content, err := templ.Render()
|
||||
assertEqual(t, err, nil)
|
||||
expected := `<h1>my new post</h1>
|
||||
<h2>a blog post</h2>
|
||||
<ul>
|
||||
<li>software</li>
|
||||
<li>web</li>
|
||||
</ul>
|
||||
`
|
||||
assertEqual(t, string(content), expected)
|
||||
}
|
||||
|
||||
func TestRenderOrg(t *testing.T) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
func TestRenderLiquidLayout(t *testing.T) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
func TestRenderOrgLayout(t *testing.T) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
func TestRenderLayoutLayout(t *testing.T) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// ------ HELPERS --------
|
||||
|
||||
func newFile(name string, contents string) *os.File {
|
||||
|
|
Loading…
Reference in a new issue