soasme / nim-mustache

Mustache in Nim

Home Page:https://mustache.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

static context

sdmcallister opened this issue · comments

commented

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?

commented

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.

commented

Close the issue. See doc