下面是示例Phoenix應用程序的路由器模塊。我想在宏之後注入模塊的完整代碼注入函數。如何使用Elixir宏獲取模塊的完整生成代碼
我試過類似Macro.to_string (Macro.expand (Code.string_to_quoted! File.read!("web/router.ex")), __ENV__)
的東西,但是它並沒有完全展開這些宏。我如何遞歸地擴展每個宏,即pipeline
,plug
,scope
, pipe_through
和get
。
感謝
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
太糟糕了,我們不能有靈藥代碼,但因爲我可以讀erlang比elixir更適合我:)謝謝 – niahoo