Skip to content

Instantly share code, notes, and snippets.

@bryanjos
Created October 6, 2015 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanjos/d392b16616ac49ba5ccc to your computer and use it in GitHub Desktop.
Save bryanjos/d392b16616ac49ba5ccc to your computer and use it in GitHub Desktop.
React Macro
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