Skip to content

Instantly share code, notes, and snippets.

@hackvan
Created September 12, 2018 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hackvan/af362c4afa3318c7b31447b47fe96c96 to your computer and use it in GitHub Desktop.
Save hackvan/af362c4afa3318c7b31447b47fe96c96 to your computer and use it in GitHub Desktop.
class HTML
def self.method_missing(method_name, *args, &block)
tag(method_name, *args, &block)
end
def self.tag(tag_name, *args, &block)
"<#{tag_name}>#{args.last} #{yield if block_given?}</#{tag_name}>"
end
end
html = HTML.div do
HTML.header do
HTML.h1 "Titulo de la página"
end +
HTML.article do
HTML.p "Hola a todos"
end
end
# <div>
# <header>
# <h1>Titulo de la página</h1>
# </header>
# <article>
# <p>Hola a todos</p>
# </article>
# </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment