-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from elixir-web/elixir-0.13.2
Merge elixir-0.13.2 into master
- Loading branch information
Showing
6 changed files
with
92 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,46 @@ | ||
|
||
defexception WeberControllerException, [:message] do | ||
def exception([value: value]) do | ||
WeberControllerException[message: value] | ||
end | ||
end | ||
|
||
defmodule Weber.Controller do | ||
|
||
defmacro __using__(_) do | ||
quote do | ||
import Weber.Controller.Layout | ||
import unquote(__MODULE__) | ||
layout('Main.html') | ||
@before_compile unquote(__MODULE__) | ||
@render_on_raise [] | ||
end | ||
end | ||
|
||
end | ||
defmacro __before_compile__(env) do | ||
render_on_raise = Module.get_attribute(env.module, :render_on_raise) | ||
|
||
quote do | ||
def raise_keys do | ||
unquote(render_on_raise) |> Enum.map(fn({k, v}) -> k end) | ||
end | ||
|
||
def render_value_for_key(key) do | ||
{_, value} = unquote(render_on_raise) |> Enum.find(fn({k, v}) -> k == key end) | ||
value | ||
end | ||
end | ||
end | ||
|
||
defmacro render_when_raise(value, result) do | ||
result = Macro.escape(result) | ||
quote do | ||
@render_on_raise [{unquote(value), unquote(result)} | @render_on_raise] | ||
end | ||
end | ||
|
||
def raise_and_render(value) do | ||
raise WeberControllerException, value: value | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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