Skip to content
This repository has been archived by the owner on Nov 27, 2018. It is now read-only.

Provide a way to add multiple content handlers #63

Open
naholyr opened this issue Jan 29, 2013 · 8 comments
Open

Provide a way to add multiple content handlers #63

naholyr opened this issue Jan 29, 2013 · 8 comments

Comments

@naholyr
Copy link

naholyr commented Jan 29, 2013

We can have many helpers, hooks, etc… but only one content handler, this makes it quite uneasy to append new content handlers above existing ones. For example in my case I use:

  • my dedicated custom content handler for some specific pages, which falls back to…
  • a content handler generating RSS, itself using…
  • blog-content-handler, which falls back to…
  • default content handler

Maybe the content_handler(s?) option could be an array, and core would:

  • unshift default content handler (so it's always here, cannot be disabled, or another option?)
  • concatenate all their "getSections" & co
  • for every negotiation: call all "negotiateContent", and merge provided contents (in the same order, last handler = most priority)

I don't think this would be too hard to do. What do you think? Do you see major issues with this vision (before I start working on PR)?

@adrinux
Copy link

adrinux commented Jan 29, 2013

I can't comment on the specifics (I just don't have that great an understanding) but I have developed a feeling that Punch's content processing is a bit limited and simplistic. Being able to stack handlers would help. As would being able to run helpers on content before handlers, rather than just in templates.

Most of the issues can be got around by writing custom content handlers but those are harder to re-use on different projects and you can't share with the wider community so easily.

@laktek
Copy link
Owner

laktek commented Jan 29, 2013

The recommended way to have multiple content handlers is by using the delegation pattern. If you look at the blog-content-handler's code it's implemented this way (by delegating to default content handler when it cannot handle something).

I will write a better tutorial to make this more clear.

@adrinux I'm considering on the idea of making helpers accessible from content handler. Will do some experimentation on that.

@naholyr
Copy link
Author

naholyr commented Jan 29, 2013

Delegation can't be enough, it prevents building efficient third party content handlers. Let's take an example:

  • I've built a content handler generating RSS, working as an overlay to punch-blog-content-handler.
  • I plan building something similar to handle comments (one that will extend content returned by getPosts for example).
  • What if I want to use them both on same time? No way else than editing one of them to delegate to the other instead of delegating to blog-content-handler :( Same applies each time I will want to use two third-party content handlers.

Maybe we could address this issue by providing a helper or snippet to allow configuring delegation (I could say in config.json that I want comments-content-handler to delegate to rss-content-handler instead of directly blog-content-handler, and it would be enough). But in the end, it will the same than providing an ordered list of handlers instead of a single one ;)

Well, actually I'll make my RSS generator a generator_hook, but the need still is here in my opinion. That's why I was wondering if there was a true limit or if there was some space for extra work ;)

@laktek
Copy link
Owner

laktek commented Jan 31, 2013

I guess what we need here is a routes-content-handler which can sit on the top and do the delegation based on the URL paths.

I'll try to make it to work during the weekend.

@naholyr
Copy link
Author

naholyr commented Jan 31, 2013

Oh yeah that could do the trick very nicely, perfect idea! Keep in touch :)

@frankct310
Copy link

Just as another use for the content handler: I'm currently working on a content handler that, given a picasa album name in the original json expands that json by including urls to the images in that album. I can do this with the current delegation, however I don't think a routes-content-handler will help me here. Or should I be doing this in a completely different way?

@naholyr
Copy link
Author

naholyr commented Feb 11, 2013

Why can't delegation work here ? Your negotiateContent calls the original
one, expands content, and run callback. Won't it work ? I agree though that
I'm not fond of this principle because the notion of "base content handler"
is very project-specific and if you want to share your plugin you will have
to let user be able to configure it (dependance injection or module's name
in configuration).
Le 11 févr. 2013 23:53, "frankct310" notifications@github.com a écrit :

Just as another use for the content handler: I'm currently working on a
content handler that, given a picasa album name in the original json
expands that json by including urls to the images in that album. I can do
this with the current delegation, however I don't think a
routes-content-handler will help me here. Or should I be doing this in a
completely different way?


Reply to this email directly or view it on GitHubhttps://github.com//issues/63#issuecomment-13408280.

@frankct310
Copy link

Content delegation does work, but the routes-content-handler will not. I was hoping to provide some more input here with other use cases. Thanks for the input, though!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants