Created
January 29, 2014 22:18
-
-
Save carlwoodward/8698305 to your computer and use it in GitHub Desktop.
Mini router for elixir.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MiniApp do | |
defmodule Router do | |
@route_stack [] | |
defmacro __using__(_opts) do | |
quote do | |
import unquote(__MODULE__) | |
end | |
end | |
defmacro get(path, contents) do | |
quote do | |
push :get, path, contents | |
end | |
end | |
defp push(via, path, contents) do | |
options = [via: via, path: path, do: contents] | |
@route_stack [options | @route_stack] | |
end | |
end | |
defmodule ApplicationRouter do | |
use MiniApp.Router | |
get "/test" do | |
IO.puts "GET" | |
{ :ok } | |
end | |
end | |
defmodule ProjectsRouter do | |
use MiniApp.Router | |
end | |
end | |
ExUnit.start | |
defmodule MiniAppTest do | |
use ExUnit.Case | |
test "truth" do | |
assert true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment