Packages
drab
0.7.1
0.10.5
0.10.4
0.10.3
0.10.2
0.10.1
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.3
0.8.2
0.8.1
0.8.0
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.3
0.6.2
0.6.1
0.6.0
0.6.0-pre.1
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.1
0.4.0
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.6
0.2.5
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Remote controlled frontend framework for Phoenix.
Current section
Files
Jump to
Current section
Files
lib/drab/controller.ex
defmodule Drab.Controller do
@moduledoc """
Turns on the Drab Commander on the pages generated by this controller.
To enable Drab on the specific page, you need to add the directive `use Drab.Controller` to the corresponding
controller first, the `use Drab.Commander` in the commander module.
defmodule DrabExample.PageController do
use Example.Web, :controller
use Drab.Controller
def index(conn, _params) do
render conn, "index.html"
end
end
By default Drab searches for the Commander with the name corresponding to the Controller, eg. NameController -
NameCommander. You may specify the commander module by using `commander` option:
use Drab.Controller, commander: MyApp.NameController
See also `Drab.Commander`
"""
defmacro __using__(options) do
quote bind_quoted: [options: options] do
Module.put_attribute(__MODULE__, :__drab_opts__, options)
unless Module.defines?(__MODULE__, {:__drab__, 0}) do
def __drab__() do
# default commander is named as a controller
controller_path = __MODULE__ |> Atom.to_string() |> String.split(".")
commander = controller_path |> List.last() |> String.replace("Controller", "Commander")
commander = controller_path |> List.replace_at(-1, commander) |> Module.concat()
view = controller_path |> List.last() |> String.replace("Controller", "View")
view = controller_path |> List.replace_at(-1, view) |> Module.concat()
Enum.into(@__drab_opts__, %{commander: commander, view: view, controller: __MODULE__})
end
end
end
end
end