defmodule Pow.Phoenix.HTML.Bootstrap do @moduledoc """ Module that helps build HTML for Phoenix with Bootstrap CSS. """ import Pow.Phoenix.HTML.FormTemplate, only: [inspect_key: 1] @form_template EEx.compile_string( """ <%%= form_for @changeset, @action, [as: :user], fn f -> %> <%%= if @changeset.action do %>

Oops, something went wrong! Please check the errors below.

<%% end %> <%= for {label, input, error} <- inputs, input do %>
<%= label %> <%= input %> <%= error %>
<% end %>
<%%= submit <%= inspect button_label %>, class: "btn btn-primary" %>
<%% end %> """) @doc """ Renders a form. """ @spec render_form(list(), binary()) :: Macro.t() def render_form(inputs, button_label) do inputs = for {type, key} <- inputs, do: input(type, key) unquote(@form_template) end defp input(:text, key) do {label(key), ~s(<%= text_input f, #{inspect_key(key)}, class: "form-control" %>), error(key)} end defp input(:password, key) do {label(key), ~s(<%= password_input f, #{inspect_key(key)}, class: "form-control" %>), error(key)} end defp label(key) do ~s(<%= label f, #{inspect_key(key)}, class: "control-label" %>) end defp error(key) do ~s(<%= error_tag f, #{inspect_key(key)} %>) end end