Skip to content

Instantly share code, notes, and snippets.

@abhihooq
Forked from kana-sama/1.ex
Created September 18, 2019 03:46
Show Gist options
  • Save abhihooq/f2262ad1d3a81b986d720438bc27e6f9 to your computer and use it in GitHub Desktop.
Save abhihooq/f2262ad1d3a81b986d720438bc27e6f9 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