nim-mustache icon indicating copy to clipboard operation
nim-mustache copied to clipboard

static context

Open sdmcallister opened this issue 3 years ago • 1 comments

I really like using nim-mustache with jester.

In the docs the jester example shown works really well for dev. But now I want to not read the context for each request.

I've done something like this with the idea to load everything to memory:

when defined(release):
  const account = staticRead"./tmpl/account.mustache"
  const addexercise = staticRead"./tmpl/stuff.mustache"
  const partials = {
    "account": account,
    "stuff": addexercise
  }.toTable()

# get "/":
  when not defined(release):
      let c = newContext(searchDirs = @["./tmpl"])
    else:
      let c = newContext(partials=partials)

Just wondering if this has come up and others are doing to optimize?

sdmcallister avatar Feb 21 '22 22:02 sdmcallister

One thing I can think of is to provide a utility function that recursively load all .mustache files from a given searchDirs and convert it into a partials Table.

soasme avatar Mar 04 '22 21:03 soasme

Close the issue. See doc

soasme avatar Mar 19 '23 19:03 soasme