Created
April 28, 2014 12:39
-
-
Save alco/11370618 to your computer and use it in GitHub Desktop.
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
defmodule View do | |
defrecord Page, [templates: []] | |
defmacro __using__(_) do | |
template = """ | |
<%= for template <- page.templates do %> | |
<%= template.id %> :: | |
<% end %> | |
<%= if true do %> | |
Hello | |
<% end %> | |
""" | |
body = EEx.compile_string(template, []) | |
quote context: nil do | |
def render() do | |
page = unquote(__MODULE__).Page[] | |
unquote(body) | |
end | |
end | |
end | |
end | |
defmodule Page do | |
use View | |
end | |
Page.render |
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
λ elixir eex_fail.ex | |
eex_fail.ex:26: warning: variable '_@4' exported from 'case' (line -1) | |
** (MatchError) no match of right hand side value: "\n\n" | |
eex_fail.ex:26: Page.render/0 | |
(elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2 | |
(elixir) lib/code.ex:303: Code.require_file/2 |
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
λ elixir eex_fail.ex | |
eex_fail.ex:26: warning: variable '_@5' exported from 'case' (line -1) | |
** (CompileError) eex_fail.ex:1: function page/0 undefined | |
(stdlib) lists.erl:1336: :lists.foreach/2 | |
eex_fail.ex:25: (file) | |
(elixir) src/elixir_lexical.erl:17: :elixir_lexical.run/2 | |
(elixir) lib/code.ex:303: Code.require_file/2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment