team-formalist / formalist-rb

Flexible form builder
MIT License
22 stars 4 forks source link

Support call time embedded form renderer options. #95

Closed narinda closed 2 years ago

narinda commented 2 years ago

Allow additional options to be passed to the EmbeddedFormRenderer after the object has been initialized.

A #with method has been added to EmbeddedFormRenderer that allows additional options to be configured. The method creates a copy of the class with the new options merged in.

For example In our hanami app we have a context helper that renders components. This allows us to access context methods like current_url from our component templates by configuring it with the current context:

component_form_renderer.with(context: self).(component_data)

andrewcroome commented 2 years ago

I checked this out locally to play and it looks like the embedded form renderer specs might need to be updated to satisfy this change @narinda.

narinda commented 2 years ago

I checked this out locally to play and it looks like the embedded form renderer specs might need to be updated to satisfy this change @narinda.

Thanks @andrewcroome, I've updated the specs.

narinda commented 2 years ago

Sweet. Ah, yep, this is breaking change I guess as anything calling that method with a hash will need to put the hash in {} for things to continue to work.

@andrewcroome Hmm yeah, I wonder if in that case a better implementation might be a #with method that returns a copy of the object with additional options:

component_form_renderer.with(context: self).call(data)

andrewcroome commented 2 years ago

@narinda yeah, that might be a good way forward.

narinda commented 2 years ago

@narinda yeah, that might be a good way forward.

@andrewcroome I've done that now, and it's been tested in a branch in our app. LMK if it looks ok to you.