jonschlinkert / templates

System for creating and managing view collections, rendering, engines, routes and more. See the "dev" branch for most recent updates.
MIT License
60 stars 9 forks source link

preRender and preCompile methods not setting data on file.data #23

Closed dtothefp closed 8 years ago

dtothefp commented 8 years ago

I had assemble-core shrink wrapped since 0.17.1. Upon upgrading data added to file.data in preRender and preCompile does not seem to persist into my Nunjucks template context. Front-matter added in onLoad seems to work though.

https://github.com/dtothefp/assemble-view-issue

Run npm start and see that any data added in preRender and preCompile is undefined

jonschlinkert commented 8 years ago

Hey @dtothefp, taking a look now. In the meantime a couple things one thing stands out

does not seem to persist into my Nunjucks template context

Did you know that this is loading those files from the file system and re-merging them for every middleware call?

jonschlinkert commented 8 years ago

@dtothefp is there something special I need to do to get this to run? I get:

npm ERR! Darwin 15.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
npm ERR! node v6.2.0
npm ERR! npm  v3.8.9
npm ERR! code ELIFECYCLE
npm ERR! assemble-view-issue@1.0.0 start: `node ./index.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the assemble-view-issue@1.0.0 start script 'node ./index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the assemble-view-issue package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs assemble-view-issue
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls assemble-view-issue
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/jonschlinkert/dev/assemble/_debugging/assemble-view-issue/npm-debug.log
jonschlinkert commented 8 years ago

It looks like the data is on ctx['global-data'] not ctx.globalData, but you're not camelcasing the file name. Not sure about page-data yet

jonschlinkert commented 8 years ago

I was able to run it btw. I'm still looking at the code, but I'm thinking the issue has something to do with your setup in tags/debug.js.

If you comment out this code then inspect file.data in a post-render middleware:

app.postRender(/./, (file, next) => {
  console.log(file.data);
  next();
});

the data is there on file.data.

dtothefp commented 8 years ago

Hey that's weird that the data is there in postRender but is not in my template context. Not sure what is going on but this is a significant divergence from when I last updated from 0.17.1

assemble-core@latest
screen shot 2016-07-11 at 9 40 22 am
assemble-core@0.17.1
screen shot 2016-07-11 at 9 43 38 am

You can see in the above screenshots in iron-node that in latest none of the data added in the middleware is present on context.ctx but in 0.17.1 it is. Therefore, I cannot access that data in my templates so the fact that is there in postRender doesn't really help me

jonschlinkert commented 8 years ago

Not sure what is going on but this is a significant divergence

Nunjucks must do something different than other engines we've tested. @doowb and I played around with your code and got everything working just by changing your config, but we also have some ideas for something we can do in templates to make it more flexible so you don't need to think about it too much.

I'll talk to @doowb, we might be able to do this now

dtothefp commented 8 years ago

@jonschlinkert I just confirmed that the breaking change was introduced into templates@0.20.0. I'm working on finding the exact commit.

What config change did you make to get it working....was it to the initial nunjucks config?

We have a huge project launching end of this week and would like to upgrade before then otherwise it might be hard and we could end up locked on an old version

dtothefp commented 8 years ago

@jonschlinkert looks like this is the commit that did it. Not sure how it made it's way into assemble-core@0.20.0 unless you did a npm publish I'm not seeing

https://github.com/jonschlinkert/templates/commit/305c700f9105b6a306a603d898daa28f706af9b6

dtothefp commented 8 years ago

sorry, I lied it's actually this commit https://github.com/jonschlinkert/templates/commit/e54e448d000b7e0ef573df497f8f2153857379cd which makes way more sense cause it was in the 0.20.0 release

jonschlinkert commented 8 years ago

Working on something. Give me a few mine. In the meantime, here is a screen I just took using engine-base instead of nunjucks, just to show that this works usually:

example