Skip to content

Latest commit

 

History

History
95 lines (68 loc) · 3.78 KB

CONTRIBUTING.md

File metadata and controls

95 lines (68 loc) · 3.78 KB

Contributing

By participating in this project, you agree to abide by the thoughtbot code of conduct.

Fork the repo:

git clone git@github.com:seanpdoyle/view_partial_form_builder.git

Set up your machine:

bin/setup

Make sure the tests pass:

bin/rails test

Make your change. Write tests. Make the tests pass:

bin/rails test

Mention how your changes affect the project to other developers and users in the CHANGELOG.md file.

  1. Write a good commit message.
  2. Push to your fork.
  3. Submit a pull request.

Architecture

Integration with ActionView, form_with, form_for, and Rails in general hinges on the ViewPartialFormBuilder::Engine configuring ViewPartialFormBuilder::FormBuilder as the host application's default_form_builder within an ActiveSupport.on_load(:action_controller_base) block.

According to the documentation:

calls with :action_controller_base hooks will be called in the context of ActionController::Base (that means self will be an ActionController::Base).

Once configured as the default <form> builder, ViewPartialFormBuilder::FormBuilder overrides various <form>-field- builder instance methods (for example, #label, #text_field, #submit) so that they first check for the existence of a matching ActionView partial template.

When a partial template exists, render it. During rendering, the partial is rendered either as a partial:, or as a layout:, depending on if the call site invoked the method with a block or not.

The ViewPartialFormBuilder::FormBuilder will render the template, making all of its arguments available to the template through the locals: option. Within the view partial, the arguments will be available:

  • by name (for example, method, options)
  • as part of the arguments array
  • through the local_assigns hash

When a partial template does not exist, the ViewPartialFormBuilder::FormBuilder falls back to rendering fields by delegating to its ancestor's methods.

Additionally, This commit removes various Rails-generated files configurations that are not necessary for ActionView integration.

Testing

Tests that inherit from FormBuilderTestCase can declare ActionView templates (with #declare_template) and #render them without needing access to Dummy::Application or an ActionController::Base instance.

Additionally, tests that cover general integration, and test covering the test hardness' Dummy::Application controller actions mixin the TemplateDeclarationHelpers module for declaring ActionView partial templates direclty in-line within test blocks.