ForageWeb.ForageView.__using__

You're seeing just the macro __using__, go back to ForageWeb.ForageView module for more information.
Link to this macro

__using__(options)

(macro)

Imports functions from ForageWeb.ForageView and defines a number of functions specialized for the given resource.

Expects the following options:

  • :routes_module (required) - ...
  • :error_helpers_module (required) - ...
  • :prefix (required) - ...
  • :prefixes (optional) - ...

This macro defines a number of functions specialized to the parameters above. Some of those functions are indicated as callbacks for the ForageWeb.ForageView behaviour (because ForageView will always define them) and some of them are not because the function name may depend on the prefixes.

Questionable design decisions

Some design decisions are a little bit questionable and deserve a longer explanation.

It might seem weird that we are defining so many functions so similar to the ones defined in Forage.ForageView itself. Forage uses Bootstrap4 templates and Forage widgets are based on the default Phoenix.HTML widgets. To deal with errors, Phoenix requires an ErrorHelpers module (defined by default by the phx.new generator), and Bootstrap requires the ability to inject the (translated) errors into the form group. This means that the ForageWeb.ForageView.forage_form_group/6 widget (and similar ones) need to be aware of the ErrorHelpers. This means that the user has to pass the ErrorHelpers module as an argument to all form groups, which would clutter the code for little benefit. By defining a ForageWeb.ForageView.forage_form_group/5 function which already incorporates the ErrorHelpers module, we can make for (slightly) cleaner code. By default, you should never have to use the

The way Bootstrap and Phoenix deal with internationalization requires an ErrorHelpers modules and the ability to inject the ForageWeb.ForageView.forage_form_group/6 function and should always use the ForageWeb.ForageView.forage_form_group/5 function instead (and similar ones)

TODO: complete this.

Examples

defmodule AppWeb.Backoffice.EmployeeView do
  use AppWeb, :view

  use ForageWeb.ForageView,
    routes_module: Routes,
    error_helpers_module: AppWeb.ErrorHelpers,
    prefix: :backoffice_employee,
    prefixes: [
      backoffice_department: MyApp.Backoffice.Department,
      backoffice_function: MyApp.Backoffice.Function,
      backoffice_benefit: MyApp.Backoffice.Benefit
    ]
end