Repository navigation
Decorator namespace option (second attempt) - #499
urbanautomaton wants to merge 2 commits into
Conversation
To make the splitting up and passing on of options hashes more understandable, constants are defined in relevant places to show the options each object will accept.
To use different decorators in different contexts (e.g. HTML rendering
vs. API representation), the ability to specify a decorator namespace is
added. For example:
> Product.new.decorate
=> #<ProductDecorator:0x0000010b6e47e8>
> Product.new.decorate(:namespace => HTML)
=> #<HTML::ProductDecorator:0x0000010b6e47e9>
Second attempt, following drapergem#480 and drapergem#494.
|
Hi @urbanautomaton, thanks heaps for this. I have a slightly different approach underway that doesn't require an extra option at all; actually, I am keen to eliminate the existing options if I can (maybe in 2.0!), they're a bit of a pain! So I hope you don't mind if I give this a close for now and see how my alternative method pans out... I'll revisit this if I don't get anywhere with it. Sorry! |
|
No worries - we're using our own fork anyway in the interim so it's not wasted effort. And yeah, I agree about the existing options, they do seem a bit superfluous. That's the thing with options hashes, it's so easy to add one more, and one more... Looking forward to seeing what you come up with... 👍 |
Truth! |
|
Hi there - I'm just going over some of the gem forks I maintain in our project, and I thought I'd check back in on this one. How did the alternative approach you mentioned for this feature pan out? If there's work in progress I could potentially help out on, I'd be happy to do so. On the other hand if you've decided it's not something you want to support after all, that's cool too. :-) |
|
Why don't you include this super useful feature in current master? Yes, it has not the best implementation, but at least it works! |
|
Hi @dhampik - I'm actually with @haines on this one. I wrote this patch to fit in with the existing implementation, but if that's not the direction draper's going in the long term, releasing it and having users start to depend on it will be a big obstacle to future refactorings. You're obviously very welcome to use my fork - I can't promise much in the way of support for it (although I'll take a look at any issues raised), but it's been stable for us for quite a while now. I don't know if this patch will still apply to the latest stable release; if I get some time in the next week or so I'll have a look. |
|
Hi @urbanautomaton thanks for reply |
Hi,
Since the namespace feature has been reverted, I've taken a second stab at it here. As @haines mentions in #480, the original changes did end up touching more of the codebase than ought to have been necessary.
This was partly due to the regular checking of valid options keys in the existing codebase, combined with the way the different entry-points support different combinations of options. Because this was hard-coded at each point (this is an example of what I mean), namespace options handling ended up in a lot of places it didn't belong.
This time I've approached the problem in two parts:
I've kept the options-handling changes separate from the addition of the namespace option for easier review. As you can see, with the options constants available, the changes necessary to actually add the namespace option are much more localised - the only places the namespace option is actually referred to (outside tests and documentation) are the definition of
Decoratable::VALID_OPTIONS, and theDecoratable.decorator_classandDecorator.collection_decorator_classmethods.Any thoughts and feedback much appreciated...
Cheers,
Simon