bminer / node-blade

Blade - HTML Template Compiler, inspired by Jade & Haml
Other
320 stars 28 forks source link

Meteor: Strange/buggy behavior using include within foreach on a Cursor object #176

Closed halgorithm closed 7 years ago

halgorithm commented 11 years ago

From what I understand, the filename provided to include is parsed relative to the current file's directory (not documented?). This behavior changes when using include within a foreach on a Meteor Cursor object. For example:

client/zCode/body.js

Template.body.posts = function() {
  return Posts.find().fetch(); // regular Array
};

client/views/body.blade

.container
  include 'posts/posts_list' exposing posts

client/views/posts/posts_list.blade

.posts
  foreach posts as post
    include 'post' exposing post

This code will render the 'posts/post' template three times for three posts in the Array returned by Posts.find().fetch(), as expected.

However, change Posts.find().fetch() to just Posts.find() (which returns a Cursor object), and this error prints each time it tries to run the include:

Exception from Deps afterFlush function: TypeError: Property 'post' of object #<Object> is not a function
    at http://localhost:3000/packages/blade/runtime-meteor.js?8f083ece0b887fa4ad9d3d5414a440d3c931cfbc:45:30
    at Object.Spark.labelBranch (http://localhost:3000/packages/spark/spark.js?4af332696fb84f1c71f2e678ad0a267755b2b828:1114:14)
    at Object.blade.Runtime.include (http://localhost:3000/packages/blade/runtime-meteor.js?8f083ece0b887fa4ad9d3d5414a440d3c931cfbc:44:28)
    at Object.<anonymous> (http://localhost:3000/views/posts/posts_list.js?a2c2f4293497e51dde7ba06c855f41781ba24417:17:22)
    at http://localhost:3000/packages/blade/runtime.js?ceb222c66ed8f4a401a6ee92cc8985f07c98d3e4:524:23
    at wrapper (http://localhost:3000/packages/blade/runtime.js?ceb222c66ed8f4a401a6ee92cc8985f07c98d3e4:466:48)
    at null._func (http://localhost:3000/packages/spark/spark.js?4af332696fb84f1c71f2e678ad0a267755b2b828:847:9)
    at _.extend._compute (http://localhost:3000/packages/deps/deps.js?651e87591167f4286e96438ff2566ba3357bff99:129:12)
    at new Deps.Computation (http://localhost:3000/packages/deps/deps.js?651e87591167f4286e96438ff2566ba3357bff99:64:10)
    at Object._.extend.autorun (http://localhost:3000/packages/deps/deps.js?651e87591167f4286e96438ff2566ba3357bff99:255:13) 

This can be "fixed" by editing 'client/views/posts/posts_list.blade" and changing include 'post' exposing post to include 'posts/post' exposing post. It then renders the same as before. It seems like a bug to have the template path for include be dependent on whether an Array or Cursor was used, though...

bminer commented 11 years ago

Weird. I will investigate further.

bminer commented 11 years ago

The issue appears to be info.rel is not being carried over properly when using reactive calls in the foreach loop. Or, perhaps, for whatever reason, resolveFilename(info.rel + "/" + relFilename) does not begin with the string "client/views/"

Not to resurrect a dead thread/issue here, but could you simply add console.log(name) right after line 31 in this file: https://github.com/bminer/meteor-blade/blob/master/runtime-meteor.js#L31 ??

Try it then and see what prints to the console before the error message. That would be extraordinarily helpful!

bminer commented 7 years ago

Closing this issue. Dropping Blade + Meteor support for now. :(