Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom_control #289

Merged
merged 3 commits into from
Jan 14, 2017
Merged

add custom_control #289

merged 3 commits into from
Jan 14, 2017

Conversation

ThomasSevestre
Copy link
Contributor

static_control wraps the displayed value in a p tag.
This is a problem in some edge use case, when you want to display an ul element.
It leads to invalid HTML generation that is silently changed by erb / haml / slim.

This view (slim) :

= f.static_control(:my_attribute) do
  ul
    li abc
    li def

Generate something like :

...
<p></p>
<ul><li>abc</li><li>def</li><ul>
<p></p>
...

The new custom_control helper generates expected view :

...
<p>
<ul><li>abc</li><li>def</li><ul>
</p>
...

@mattbrictson
Copy link
Contributor

It seems like this PR is a different way of accomplishing the same thing as #301. Am I right?

@ThomasSevestre @antpaw which do you think is the better solution?

@antpaw
Copy link
Contributor

antpaw commented Dec 10, 2016

I don't like the name of the method, i prefer to just remove the private attribute form form_group_builder, i think it will just work they same way custom_control does but with way less code and overhead.

@ThomasSevestre
Copy link
Contributor Author

It all depends on your will to publish form_group_builder in the gem API. If you want to be able to change form_group_builder behavior without breaking the API, then you should keep it private and use a proxy method.

@antpaw
Copy link
Contributor

antpaw commented Dec 12, 2016

How does removing this method from private breaks the API? I think its not a major change, it will be the same as a new method was added?

@ThomasSevestre
Copy link
Contributor Author

If the method becomes public, future changes to the method will break the API.
It's not my gem and I don't known if it is ok or not.

@mattbrictson
Copy link
Contributor

As the de facto maintainer of this gem, I am concerned about breaking changes, but I am also concerned about support and usability of the API. For me, the method name form_group_builder is not very intuitive and the difference between form_group and form_group_builder is subtle and could confuse people.

I would prefer we make a new public method with a good, self-explanatory name. How we structure the implementation is less important: it could even just be a public alias of form_group_builder.

form_group_builder(name, options) do
capture(&block)
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this accomplish the same thing? Do we need the extract_options! and capture?

def custom_control(name, options={}, &block)
   form_group_builder(name, options, &block)
end

Copy link
Contributor Author

@ThomasSevestre ThomasSevestre Dec 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract_options! is not needed. I've copied static_control to have the same ergonomy. It allows this kind of things:

= custom_control label: 'MyLabel' do
  ...

capture is not needed since it is already done in form_group

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see... So in order to support the example you described (custom_control label: 'MyLabel'), then we do need extract_options!. Right?

capture is not needed since it is already done in form_group

Agreed. Can you update the PR to remove it?

@mattbrictson
Copy link
Contributor

@ThomasSevestre I'd still like merge this PR if you are interested. Could you review the latest code comments and provide an update? Thanks

@ThomasSevestre
Copy link
Contributor Author

ThomasSevestre commented Jan 12, 2017

@mattbrictson Sorry for my late reply, I've removed capturecall and kept extract_options!

@mattbrictson
Copy link
Contributor

Thanks! 🙇

@mattbrictson mattbrictson merged commit dccdb60 into bootstrap-ruby:master Jan 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants