carrot / roots-dynamic-content

Dynamic content extension for roots v3
http://roots.cx
Other
33 stars 15 forks source link

Little issue on all() method #7

Open nanotime opened 10 years ago

nanotime commented 10 years ago

Guys, i found a new issue on the all() method. When someone try to get all posts or some nested dynamic content, like:

!=JSON.stringify(site.posts.all())

If the post folder don't have a .jade file to render out of nested folders, the prompt return:

Object  has no method 'all'
  at Error (<anonymous>:null:null)
  at on_error (/usr/local/lib/node_modules/roots/lib/cli/watch.js:67:21)
  at Roots.<anonymous> (/usr/local/lib/node_modules/roots/lib/cli/watch.js:45:14)
  at Roots.EventEmitter.emit (events.js:95:17)
  at Compile.<anonymous> (/usr/local/lib/node_modules/roots/lib/api/compile.js:66:20)
  at tryCatchReject (/usr/local/lib/node_modules/roots/node_modules/when/lib/makePromise.js:790:14)
  at RejectedHandler.when (/usr/local/lib/node_modules/roots/node_modules/when/lib/makePromise.js:658:9)
  at DeferredHandler.run (/usr/local/lib/node_modules/roots/node_modules/when/lib/makePromise.js:444:13)
  at Scheduler._drain (/usr/local/lib/node_modules/roots/node_modules/when/lib/scheduler.js:56:14)
  at Scheduler.drain (/usr/local/lib/node_modules/roots/node_modules/when/lib/scheduler.js:21:9)
  at process._tickCallback (node.js:415:13)

So, more clear:

posts
  nested
    bleh
  nested2
    bleh

Will be: ERAAAWWWRRR! Bitch

posts
  bleh-not-nested <-- not nested .jade file
  nested
    bleh
  nested2
    bleh

Will be: Fuck yeah!

Annd, I realized that the test (in dynamic-content project) is not covered the case of a nest without .jade files above.

So, this is it, If I can, I will write a test just to prove that part ... I just need to read the documentation and I pray that everything goes well, I have never written tests.

Cheers!!!

jescalan commented 10 years ago

Ahh nice catch! Thank you - and very clear writeup as well. Will try to have this resolved in the next release!

nanotime commented 10 years ago

Thanks! I just try to be useful (?) I don't know what (or how) say that xD

Anyway

jescalan commented 10 years ago

Haha "Just trying to be helpful" I think would be the right call! I also speak spanish if that's easier or quicker for you as well, although I'm sure your english is better than my spanish

nanotime commented 10 years ago

Google translate is better for spanish-english ... so let me speak english, maybe someday i can speak that well... i hope.

So, if you want to close this issue, go ahead... or maybe when the bug got fixed.

Damn i need to have more practice...

nanotime commented 10 years ago

Hey, i have a "solution"... isn't a real solution but just need to create a dummie file, like dummie.jade in the root folder of your dynamic content file and put inside one line of front matter: _render: false.

And this is it, you can call all() method and render it... the dummie content will not rendered

It came to my mind just the day I posted the bug, but I forgot to mention.

Cheers! :beers:

jescalan commented 10 years ago

Yup, that should be a great workaround for now, but I will definitely try to have this issue resolved for the next release as well :grinning:

thiagodebastos commented 9 years ago

I have been struggling with this issue for quite some time now, for some reason even with the _render: false YAML front-matter it still gets rendered. Also, post._categories[-1] returns undefined, meaning I have to set it to [1] which is correct for all but the dummie.jade file, which then becomes undefined. I only just understood why that happens too!

jescalan commented 9 years ago

Ah I'm sorry, I totally forgot about this. I'll take a look into it soon. This is just a small bug that should be fixable in the code. If you want to take a look feel free -- if not I'll get to it as soon as I can!

thiagodebastos commented 9 years ago

I wish I could, I am very much a newcomer to js and node and have not much of an idea as to where to begin to look in the code, I'm sorry that I can't save you the time!

EDIT: I fixed this with some basic Jade logic using unless:

each post in site.posts.all()
  if site.posts.all(category)
    unless post.title === undefined
      ... content
nanotime commented 9 years ago

Well, hello hello! I just come here to say hi (?) ... not really, but Hi! xD

Yup, the issue persists, bad juju, and one little thing, now when i put _render: false on the front matter in the dummie content, it's rendered anyway.

For all other things, all fine.

PD: Wow, @jenius, roots has become something awesome!

edit:

Easy cheap trick, just make a jade fool's hacking and adding some extra front matter, like this:

Post that will show:

title: 'Primer post en ocio'
date: 18/04/2015
_content: false
_render: true
---

The ugly but necessary guy:

title: 'dummie'
date: 18/04/2015
_content: false
_render: false
---

The judge

each post in site.posts.all()
    article.post(style=post._render ? '' : 'display: none')
   //- bleh code
argyleink commented 9 years ago

+1