-
-
Save bryanjos/d392b16616ac49ba5ccc to your computer and use it in GitHub Desktop.
React Macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule ReactDOM do | |
@tags [ | |
:a, | |
:abbr, | |
:acronym, | |
:address, | |
:applet, | |
:area, | |
:article, | |
:aside, | |
:audio, | |
:b, | |
:base, | |
:basefont, | |
:bdi, | |
:bdo, | |
:big, | |
:blockquote, | |
:body, | |
:br, | |
:button, | |
:canvas, | |
:caption, | |
:center, | |
:cite, | |
:code, | |
:col, | |
:colgroup, | |
:command, | |
:datalist, | |
:dd, | |
:del, | |
:details, | |
:dfn, | |
:dir, | |
:div, | |
:dl, | |
:dt, | |
:em, | |
:embed, | |
:fieldset, | |
:figcaption, | |
:figure, | |
:font, | |
:footer, | |
:form, | |
:frame, | |
:frameset, | |
:h1, | |
:head, | |
:header, | |
:hgroup, | |
:hr, | |
:html, | |
:i, | |
:iframe, | |
:img, | |
:input, | |
:ins, | |
:kbd, | |
:keygen, | |
:label, | |
:legend, | |
:li, | |
:link, | |
:map, | |
:mark, | |
:menu, | |
:meta, | |
:meter, | |
:nav, | |
:noframes, | |
:noscript, | |
:object, | |
:ol, | |
:optgroup, | |
:option, | |
:output, | |
:p, | |
:param, | |
:pre, | |
:progress, | |
:q, | |
:rp, | |
:rt, | |
:ruby, | |
:s, | |
:samp, | |
:script, | |
:section, | |
:select, | |
:small, | |
:source, | |
:span, | |
:strike, | |
:strong, | |
:style, | |
:sub, | |
:summary, | |
:sup, | |
:table, | |
:tbody, | |
:td, | |
:textarea, | |
:tfoot, | |
:th, | |
:thead, | |
:time, | |
:title, | |
:tr, | |
:track, | |
:tt, | |
:u, | |
:ul, | |
:var, | |
:video, | |
:wbr | |
] | |
for tag <- @tags do | |
defmacro unquote(tag)(options \\ nil, do: inner) do | |
tag = unquote(tag) | |
inner = case inner do | |
{:__block__, _, inner_block} -> | |
inner_block | |
_ -> | |
[inner] | |
end | |
quote do | |
React.createElement(Atom.to_string(unquote(tag)), unquote(options), unquote_splicing(inner)) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment