Chapter 5Creating an HTML Domain-Specific Language

One of the most powerful ways to use macros is to build domain-specific languages (DSLs). They let you create a custom layer in the language to attack problems closer to your application domain. This can make your code easier to write and make it more clearly represent the problem being solved. With DSLs, you can codify your business requirements and operate at a shared level of abstraction with the callers of your library.

Let’s extend the tools you’ve learned so far to create an HTML DSL. We’ll start by seeing what domain-specific languages are all about. Next, we’ll build a complete HTML DSL that generates templates from pure Elixir code. While building our library, we’ll uncover a few advanced ...

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.