Restore include_template tag (#47)
This works with Fluid, and there is no reason to mandate a change; we will document the different behavior with include
This commit is contained in:
@@ -316,10 +316,14 @@ open MyWebLog.Data
|
||||
module Cache =
|
||||
|
||||
open System.Collections.Concurrent
|
||||
open System.Text.RegularExpressions
|
||||
|
||||
/// Cache of parsed templates
|
||||
let private _cache = ConcurrentDictionary<string, IFluidTemplate> ()
|
||||
|
||||
/// Custom include parameter pattern
|
||||
let private hasInclude = Regex("""{% include_template \"(.*)\" %}""", RegexOptions.None, TimeSpan.FromSeconds 2L)
|
||||
|
||||
/// <summary>Get a template for the given theme and template name</summary>
|
||||
/// <param name="themeId">The ID of the theme for which a template should be retrieved</param>
|
||||
/// <param name="templateName">The name of the template to retrieve</param>
|
||||
@@ -336,8 +340,25 @@ module Cache =
|
||||
| Some theme ->
|
||||
match theme.Templates |> List.tryFind (fun t -> t.Name = templateName) with
|
||||
| Some template ->
|
||||
_cache[templatePath] <- parser.Parse(template.Text)
|
||||
return Ok _cache[templatePath]
|
||||
let mutable text = template.Text
|
||||
let mutable childNotFound = ""
|
||||
while hasInclude.IsMatch text do
|
||||
let child = hasInclude.Match text
|
||||
let childText =
|
||||
match theme.Templates |> List.tryFind (fun t -> t.Name = child.Groups[1].Value) with
|
||||
| Some childTemplate -> childTemplate.Text
|
||||
| None ->
|
||||
childNotFound <-
|
||||
if childNotFound = "" then child.Groups[1].Value
|
||||
else $"{childNotFound}; {child.Groups[1].Value}"
|
||||
""
|
||||
text <- text.Replace(child.Value, childText)
|
||||
if childNotFound <> "" then
|
||||
let s = if childNotFound.IndexOf ";" >= 0 then "s" else ""
|
||||
return Error $"Could not find the child template{s} {childNotFound} required by {templateName}"
|
||||
else
|
||||
_cache[templatePath] <- parser.Parse(text)
|
||||
return Ok _cache[templatePath]
|
||||
| None ->
|
||||
return Error $"Theme ID {themeId} does not have a template named {templateName}"
|
||||
| None -> return Error $"Theme ID {themeId} does not exist"
|
||||
|
||||
Reference in New Issue
Block a user