Support custom template locals - #167
Conversation
krzysdz
left a comment
There was a problem hiding this comment.
I just read #42 and it seems clear to me that this solution is not desired:
Hi! The point of the rendering is to be independent of any interaction and creating side-effects from the request, thus why we do not provide the
reqandres.
Originally posted by @dougwilson in #42 (comment)
An alternative has been provided in #42 (comment)
|
Thanks for the review. I updated the approach to avoid passing The current diff now follows the alternative pattern from #42: callers can provide static I also updated the README and added focused coverage for:
Local verification passed with the commands listed in the PR body. |
Fixes #42.
This adds a way to pass additional data into custom template functions without exposing
reqorresto the renderer:options.localsprovides static template locals.req.localsprovides request-scoped locals from upstream middleware.directory,fileList,path,style, andviewNamecannot be overridden accidentally.This preserves the existing template callback signature and keeps rendering independent from direct request/response side effects.
Verification:
./node_modules/.bin/mocha --reporter spec --check-leaks test/ --grep 'locals'npm testnpm run lintgit diff --check master..HEAD