View Source Routex.Processing (Phoenix Routes Extension Framework v0.3.0-alpha.4)

This module provides everything needed to process Phoenix routes. It executes the transform callbacks from extensions to transform Phoenix.Router.Route structs and create_helpers callbacks to create one unified Helper module.

Powerful but thin Although Routex is able to influence the routes in Phoenix applications in profound ways, the framework and it's extensions are a suprisingly lightweight piece of compile-time middleware. This is made possible by the way router modules are pre-processed by Phoenix.Router itself.

Prior to compilation of a router module, Phoenix Router registers all routes defined in the router module using the attribute @phoenix_routes. Each route is at that stage a Phoenix.Router.Route struct.

Any route enclosed in a preprocess_using block has received a :private field in which Routex has put which Routex backend to use for that particular route. By enumerating the routes, we can process each route using the properties of this configuration and set struct values accordingly. This processing is nothing more than (re)mapping the Route structs' values.

After the processing by Routex is finished, the @phoenix_routes attribute in the router is erased and re-populated with the list of mapped Phoenix.Router.Route structs.

Once the router module enters the compilation stage, Routex is already out of the picture and route code generation is performed by Phoenix Router.

Summary

Functions

Callback executed before compilation of a Phoenix Router. This callback is added to the @before_compile callbacks by Routex.Router.

Checks if the callback is defined. When defined it executes the callback and returns the result , otherwise returns default.

The main function of this module. Receives as only argument the environment of a Phoenix router module.

Types

@type backend() :: module()
@type extension_module() :: module()
@type routes() :: [Phoenix.Router.Route.t(), ...]

Functions

@spec __before_compile__(Macro.Env.t()) :: :ok

Callback executed before compilation of a Phoenix Router. This callback is added to the @before_compile callbacks by Routex.Router.

Link to this function

exec_when_defined(backend, extension_module, callback, default, args)

View Source

Checks if the callback is defined. When defined it executes the callback and returns the result , otherwise returns default.

@spec execute_callbacks(Macro.Env.t()) :: :ok

The main function of this module. Receives as only argument the environment of a Phoenix router module.