How to get the full generated code of a module using Elixir macros

Viewed 1703

Below is the router module for a sample Phoenix application. I would like to see the full code of the module after macros inject functions.

I tried things like Macro.to_string (Macro.expand (Code.string_to_quoted! File.read!("web/router.ex")), __ENV__) but it doesn't fully expand the macros. How could I recursively expand every macro, i.e. pipeline, plug, scope, pipe_through and get.

Thanks

defmodule HelloPhoenix.Router do
  use HelloPhoenix.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
    plug :put_secure_browser_headers
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", HelloPhoenix do
    pipe_through :browser # Use the default browser stack

    get "/", PageController, :index
  end

end
2 Answers
Related