Skip to content

Instantly share code, notes, and snippets.

@kana-sama
Created January 23, 2017 21:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kana-sama/491ae1bd75974797d2bcb43c7489abf9 to your computer and use it in GitHub Desktop.
Save kana-sama/491ae1bd75974797d2bcb43c7489abf9 to your computer and use it in GitHub Desktop.
defmodule MyApp.Web.ComponentHelpers do
def component(template, assigns) do
MyApp.Web.ComponentView.render(template, assigns)
end
def component(template, assigns, do: block) do
MyApp.Web.ComponentView.render(template, Keyword.merge(assigns, [do: block]))
end
def c(name, assigns) do
component(template(name), assigns)
end
def c(name, assigns, opts) do
component(template(name), assigns, opts)
end
defp template(name) when is_atom(name) do
"#{name}.html"
end
end
<%= c :tabs do %>
<%= c :tab, name: "All Products" %>
<%= c :tab, name: "Featured" %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment