Formex - a form library for Phoenix inspired by Symfony

I think such a project should have an API like this:

defmodule MyApp.MyAdmin do
  use SomeMagicHere
  defresource MySchema1, options: [...]
  defresource MySchema2, options: [...]
  defresource MySchema3, options: [...]
  defresource MySchema4, options: [...]
  # ...
end

It would define controllers for the resources (using macros, no code generation). Then you’d just add the stuff to the router.

defmodule MyAppWeb.Router do
  # ...
  require MyApp.MyAdmin
  # ...

  MyApp.MyAdmin.routes "admin/"
  # ...
end

The :options would allow the user to customize some things, and even add extra controller actions. For example:

defresource User, options: [
  extra_actions: [
    change_password: &PasswordController.change_password/2
  ]
]

My idea was to have zero work for the default case (just define the schemas and you’re good to go) and incrementally more work for more advanced use cases. I think that FlaskAdmin or FlaskAppBuilder are good sources of inspiration.

They take tons of options, with varying levels of granularity depening on how much customization you need. You can change the field labels, the order of the fields, etc. They do all of this with class inheritance, of course, but it an be done by merging option dictionaries r keyword lists.

1 Like