Skip to content

Instantly share code, notes, and snippets.

@alco
Created April 28, 2014 12:39
Show Gist options
  • Save alco/11370618 to your computer and use it in GitHub Desktop.
Save alco/11370618 to your computer and use it in GitHub Desktop.
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
λ 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
λ 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