Giter Site home page Giter Site logo

Comments (16)

jonschlinkert avatar jonschlinkert commented on May 28, 2024

hmm, strange. view should definitely be there. that's not something I would change without advance notice, then a minor bump and a big "heads up" in the changelog.

as far as I know, nothing has been removed from the context since templates was created. latest is 0.15.10, have you tried that version?

from templates.

dtothefp avatar dtothefp commented on May 28, 2024

@jonschlinkert yes I tried templates 0.15.10 with assemble-core 0.14.3, still the same problem. can try to make you a small example

from templates.

jonschlinkert avatar jonschlinkert commented on May 28, 2024

actually, I'm pretty sure view was never directly on the helper context (e.g. this.view) until recently. it was always on this.context.view. Now it's on both.

however... this.context.view is non-enumerable (I'm pretty sure it always was, but it's possible it was enumerable before, in which case this would be a regression).

I just now remembered something @doowb mentioning something about view, that might have been related. @doowb, maybe you remember?

from templates.

doowb avatar doowb commented on May 28, 2024

I think I just realized what happened....

Before we returned the context object from bindHelpers and it was the same object that was used as the thisArg for helpers. Now, thisArg is different from the context that we're returning from bindHelpers.

I think we either need to add the view to the returned context (like in .compile) or add it to this context object

@dtothefp is having an issue because the context object passed into those nunjucks tags is the context that we pass into the render function... engine.render(view.contents, context). So it just needs to current view to be added.

I just now remembered something @doowb mentioning something about view, that might have been related. @doowb, maybe you remember?

This was a different issue related to the current view, but that was inside handlebars helpers and has been fixed.

from templates.

dtothefp avatar dtothefp commented on May 28, 2024

Here's an example, run node ./index.js

Breaking
https://github.com/dtothefp/assemble-view-issue
screen shot 2016-03-14 at 12 10 27 am

Working
https://github.com/dtothefp/assemble-view-issue/tree/assemble-legacy
screen shot 2016-03-14 at 12 10 33 am

from templates.

jonschlinkert avatar jonschlinkert commented on May 28, 2024

Before we returned the context object from bindHelpers

ahhh, damn. good insight @doowb. surprising that this isn't covered in like 1,200 unit tests

from templates.

doowb avatar doowb commented on May 28, 2024

however... this.context.view is non-enumerable (I'm pretty sure it always was, but it's possible it was enumerable before, in which case this would be a regression).

This is what's happening.

The .view property is on the context just like before (I missed where the reference was still kept throughout the bindHelpers method.

The issue is that it looks like nunjucks doesn't keep non-enumerable properties on the context. When I do this.context.view = view in the Context object, I see the view in the nunjucks tag, but I'm not able to even get to the view when doing ctx.view in the tag, so it must be removing it.

from templates.

doowb avatar doowb commented on May 28, 2024

I even tried adding the view to the context passed in when rendering and it didn't show up. Nunjucks must bind the context from the compile function and only use that (unless there's something else I don't know about nunjucks, which is probably the case)

from templates.

jonschlinkert avatar jonschlinkert commented on May 28, 2024

if you change it to this.context.view instead of using define did it work?

from templates.

doowb avatar doowb commented on May 28, 2024

if you change it to this.context.view instead of using define did it work?

Yes

from templates.

jonschlinkert avatar jonschlinkert commented on May 28, 2024

oh yeah sorry I see where you said that already. thx

from templates.

dtothefp avatar dtothefp commented on May 28, 2024

@doowb @jonschlinkert hey guys so what does this all mean? I don't want you to have to change your code just to accommodate nunjucks. Is this something I just shouldn't count on in the future and just bind the view context I need in an onload middleware or something?

from templates.

doowb avatar doowb commented on May 28, 2024

hey guys so what does this all mean?

Nunjucks only "sees" enumerable properties when they make a copy of the context passed in. Since we're doing something like...

Object.defineProperty(context, 'view', {
  configurable: true,
  enumerable: false,
  value: view
});

...nunjucks doesn't "see" the view property and doesn't copy it over to the context.ctx property in your tag.

just bind the view context I need in an onload middleware or something?

The following using preCompile works for nunjucks.

app.create('pages', {renameKey})
  .use(loader())
  .preCompile(/./, function(file, next) {
    file.data.view = file;
    next();
  });

This lets you use whatever property you want and put other things on the file.data object that will be accessible in your tags.

As @jonschlinkert said above...

however... this.context.view is non-enumerable (I'm pretty sure it always was, but it's possible it was enumerable before, in which case this would be a regression).

...so maybe we should make it non-enumerable.

FWIW... I found this issue on nunjucks that talks about es2105 getter syntax not working (which I think transpiles into Object.defineProperty). Looks like they'd be willing to take a PR if you find a fix 😉

from templates.

jonschlinkert avatar jonschlinkert commented on May 28, 2024

...so maybe we should make it non-enumerable.

@doowb meant "make it enumerable". yeah let's do that. I haven't looked at the nunjucks internals, but I imagine they'll need to do more than a simple object-assign on the context. getters should also be copied

from templates.

jonschlinkert avatar jonschlinkert commented on May 28, 2024

I don't want you to have to change your code just to accommodate nunjucks.

meant to reply to this. if view was enumerable before, the fact that behavior has changed for you makes this a regression. we'll make view enumerable, but in the meantime hopefully you are able to solve it for now using the solution @doowb posted

from templates.

jonschlinkert avatar jonschlinkert commented on May 28, 2024

closing since I think this was resolved a while ago. please feel free to reopen if there is still an issue

from templates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.