Skip to content

Instantly share code, notes, and snippets.

@carlwoodward
Created January 29, 2014 22:18
Show Gist options
  • Save carlwoodward/8698305 to your computer and use it in GitHub Desktop.
Save carlwoodward/8698305 to your computer and use it in GitHub Desktop.
Mini router for elixir.
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