srid / Feather

[Paused] Static site generator with customizable pipeline and live-reload
GNU Affero General Public License v3.0
5 stars 0 forks source link

Choose a dotnet HTML templating library (other than DotLiquid?) #1

Closed srid closed 3 years ago

srid commented 3 years ago

DotLiquid (current choice) doesn't work well with arbitrary JSON input, and seems to require fiddling with advanced non-F# language features like ExpandoObject.

https://github.com/dotliquid/dotliquid/issues/299#issuecomment-421527692

decision matrix

virtual fs layouts JSON input
DotLiquid 🆗 🆗 ⚠️ https://github.com/srid/Feather/issues/1#issuecomment-808852464
Scriban ❔ Differently https://github.com/scriban/scriban/issues/52#issuecomment-473706014
fluid 🆗 🆗 https://github.com/sebastienros/fluid/issues/291 🆗 https://github.com/sebastienros/fluid/issues/290

legend:

srid commented 3 years ago

fluid's author comments about DotLiquid here,

Initially I tried to use dotLiquid but was faced with performance issues as it is using regular expressions to parse the templates.

srid commented 3 years ago

JSON input is technically possible with DotLiquid, but it takes a lot of code: https://github.com/dotliquid/dotliquid/issues/223#issuecomment-497443228 and https://github.com/dotliquid/dotliquid/issues/299#issuecomment-421527692 - but it doesn't work reliably https://github.com/dotliquid/dotliquid/issues/417

srid commented 3 years ago

I should try https://github.com/sebastienros/fluid/pull/292 on Monday.

srid commented 3 years ago

FTR fluid requires the following to enable Json support, but it doesn't work in new master, and might need fixing:

        let enableJson(opts: TemplateOptions) =
            opts.MemberAccessStrategy.Register<JObject, JToken>(
                System.Func<JObject, string, JToken>(fun src name -> src.GetValue(name))
            )
            opts.ValueConverters.Add(fun x -> 
                match x with 
                | :? JObject as o ->
                    x
                | _ -> null)
            opts.ValueConverters.Add(fun x -> 
                match x with 
                | :? JValue as v ->
                    v.Value
                | _ -> null)

The JSON criteria has become much less important right now (because type-safety is a good thing in template variables) though, so I'll go ahead without working JSON support. The switch to fluid is good anyway due to performance benefits and active development.