sergeche/docpad-plugin-menu — pull request #10 by dominics (2014-01-23 03:57:26+00:00)
Title: Allow menus to be generated for dynamically filtered collections

This PR adds a new template method: `generateMenuForCollection`. This method follows *almost* the same signature as `generateMenu`, but accepts a collection instance rather than a string name.

At the moment, because of the signature of `generateMenu`, only named collections can be turned into a menu. This is limiting for the case where you'd like to be able to generate a subset of pages based on some property of the current page.

For example, if I have a file structure like that in issue #8, and I'd like to only generate menu items for pages in the current 'product' or 'topic', I'd have to list the various topics and products in my docpad configuration file (statically, and they'll get out of date should the organisation of topics change), just so I'll have a name to pass into `generateMenu`. That is, I can obtain a submenu based on the current page with:

```coffeescript
pages = @getCollection('pages').findAllLive({relativeOutDirPath: @document.relativeOutDirPath})
items = @generateMenuForCollection(@document.url, pages)
```

I could find no information about adding named collections from a document; this is a nice, easy workaround. If there is a way to add a named collection dynamically, feel free to point me toward it (but I gather the *whole point* of named collections is that they're evaluated once per generation, not once per page)