Skip to content

Decorator namespace option (second attempt) - #499

Closed
urbanautomaton wants to merge 2 commits into
drapergem:masterfrom
urbanautomaton:decorator-namespace-option-mk2
Closed

urbanautomaton wants to merge 2 commits into
drapergem:masterfrom
urbanautomaton:decorator-namespace-option-mk2

Conversation

@urbanautomaton

Copy link
Copy Markdown
Contributor

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:

  1. Set constants defining each class's valid options, and use these to validate and slice where necessary
  2. Add the namespace option.

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 the Decoratable.decorator_class and Decorator.collection_decorator_class methods.

Any thoughts and feedback much appreciated...

Cheers,
Simon

Simon Coffey added 2 commits March 13, 2013 15:29
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.
@haines

haines commented Mar 13, 2013

Copy link
Copy Markdown
Contributor

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!

@haines haines closed this Mar 13, 2013
@urbanautomaton

Copy link
Copy Markdown
Contributor Author

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... 👍

@steveklabnik

Copy link
Copy Markdown
Member

that's the thing with options hashes, it's so easy to add one more, and one more...

Truth!

@urbanautomaton

Copy link
Copy Markdown
Contributor Author

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. :-)

@dhampik

dhampik commented Dec 29, 2013

Copy link
Copy Markdown

Why don't you include this super useful feature in current master? Yes, it has not the best implementation, but at least it works!

@urbanautomaton

Copy link
Copy Markdown
Contributor Author

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.

@dhampik

dhampik commented Dec 30, 2013

Copy link
Copy Markdown

Hi @urbanautomaton thanks for reply
Actually I already decided to use my own implementation of presenters which provides full control for me.
And I took Ryan Bates' approach from this railscast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants