Further Exploration

You leveled up on your metaprogramming skills by defining a language within a language using DSLs. This style of problem solving will let you create expressive libraries that can distill a problem into a natural set of macros. You saw how some domains, like HTML generation, fall naturally into a DSL, while others require careful consideration of tradeoffs. Think about other ways you can extend the HTML DSL to make it production ready. Here are some ideas to get you started:

  • Extend the Html library with nicely formatted output:

 
iex>​ Template.render
 
"<div id=\"main\">
 
<h1 class=\"title\">Welcome!</h1>
 
</div>
 
<div class=\"row\">
 
<div>
 
<p>Hello!</p>
 
</div>
 
</div>"
  • Sanitize all text input against ...

Get Metaprogramming Elixir now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.