Skip to content

Commit f6eeead

Browse files
committed
0586 Using Macro
1 parent e5b2e26 commit f6eeead

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lectures/macros/macro_using.exs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
defmodule Html do
2+
defmacro __using__(_opts) do
3+
quote do
4+
import Html
5+
end
6+
end
7+
8+
def div(content), do: tag("div", content)
9+
10+
def p(content), do: tag("p", content)
11+
12+
def span(content), do: tag("span", content)
13+
14+
defp tag(name, content) do
15+
"<#{name}>#{content}</#{name}>"
16+
end
17+
end
18+
19+
defmodule Page do
20+
use Html
21+
def view(content) do
22+
content
23+
|> span()
24+
|> p()
25+
|> div()
26+
end
27+
end

0 commit comments

Comments
 (0)