diff --git a/lib/mix/tasks/update_mdn_docs.ex b/lib/mix/tasks/update_mdn_docs.ex index 11e2af0..9337c1e 100644 --- a/lib/mix/tasks/update_mdn_docs.ex +++ b/lib/mix/tasks/update_mdn_docs.ex @@ -6,7 +6,8 @@ defmodule Mix.Tasks.UpdateMdnDocs do @shortdoc "Update the MDN documentation" def run(_) do - IO.puts "Downloading MDN documentation" + IO.puts("Downloading MDN documentation") + (Temple.Tags.nonvoid_elements() ++ Temple.Tags.void_elements()) |> Enum.map(fn el -> Task.async(fn -> diff --git a/lib/temple.ex b/lib/temple.ex index c2ea729..970c6a2 100644 --- a/lib/temple.ex +++ b/lib/temple.ex @@ -35,17 +35,15 @@ defmodule Temple do quote do import Kernel, except: [div: 2] - Temple.Utils.lexical_scope(fn -> - {:ok, var!(buff, Temple.Tags)} = Temple.Utils.start_buffer([]) - + with {:ok, var!(buff, Temple.Tags)} <- Temple.Utils.start_buffer([]) do unquote(block) markup = Temple.Utils.get_buffer(var!(buff, Temple.Tags)) :ok = Temple.Utils.stop_buffer(var!(buff, Temple.Tags)) - markup |> Enum.reverse() |> Enum.join("") |> Phoenix.HTML.raw() - end) + Temple.Utils.join_and_escape(markup) + end end end diff --git a/lib/temple/form.ex b/lib/temple/form.ex index 2d76ef5..1a1d566 100644 --- a/lib/temple/form.ex +++ b/lib/temple/form.ex @@ -293,7 +293,9 @@ defmodule Temple.Form do form.impl.to_form(form.source, form, field, options) |> Enum.each(fn form -> Enum.map(form.hidden, fn {k, v} -> - Phoenix.HTML.Form.hidden_input(form, k, value: v) + {:safe, hidden_input} = Phoenix.HTML.Form.hidden_input(form, k, value: v) + + hidden_input end) |> Enum.each(&Utils.put_buffer(var!(buff, Temple.Tags), &1)) diff --git a/lib/temple/tags.ex b/lib/temple/tags.ex index 3381c32..2436ab7 100644 --- a/lib/temple/tags.ex +++ b/lib/temple/tags.ex @@ -43,7 +43,7 @@ defmodule Temple.Tags do input name: "comments", placeholder: "Enter a comment..." end - # {:save, + # {:safe, # "
#
#
diff --git a/lib/temple/utils.ex b/lib/temple/utils.ex index 44c18d2..adba93d 100644 --- a/lib/temple/utils.ex +++ b/lib/temple/utils.ex @@ -45,8 +45,8 @@ defmodule Temple.Utils do end end - def lexical_scope(work) do - work.() + def join_and_escape(markup) do + markup |> Enum.reverse() |> Enum.join("") |> Phoenix.HTML.raw() end def start_buffer(initial_buffer), do: Agent.start(fn -> initial_buffer end) diff --git a/test/temple/form_test.exs b/test/temple/form_test.exs index 5ba29a4..53aa256 100644 --- a/test/temple/form_test.exs +++ b/test/temple/form_test.exs @@ -56,7 +56,7 @@ defmodule Temple.FormTest do defmodule Person do use Ecto.Schema - embedded_schema do + schema "persons" do field(:name) belongs_to(:company, Company) has_many(:responsibilities, Reponsibility) @@ -66,7 +66,7 @@ defmodule Temple.FormTest do defmodule Company do use Ecto.Schema - embedded_schema do + schema "companies" do field(:name) field(:field) end @@ -75,8 +75,10 @@ defmodule Temple.FormTest do defmodule Responsibility do use Ecto.Schema - embedded_schema do + schema "responsibilities" do field(:description) + + belongs_to(:person, Person) end end @@ -110,7 +112,14 @@ defmodule Temple.FormTest do end test "generates inputs for has_many" do - person = %Person{responsibilities: [%Responsibility{}, %Responsibility{}]} + person = %Person{ + id: 1, + responsibilities: [ + %Responsibility{id: 1, person_id: 1}, + %Responsibility{id: 2, person_id: 1} + ] + } + changeset = Ecto.Changeset.change(person) action = "/" opts = [] @@ -121,7 +130,8 @@ defmodule Temple.FormTest do text_input(form, :name) inputs_for form, :responsibilities do - text_input(inner_form, :description) + phx_label(inner_form, :description) + text_area(inner_form, :description) _ = "Bob" end end diff --git a/test/temple/tags_test.exs b/test/temple/tags_test.exs index ad346d5..9b6128b 100644 --- a/test/temple/tags_test.exs +++ b/test/temple/tags_test.exs @@ -42,9 +42,7 @@ defmodule Temple.TagsTest do test "renders a #{tag} with a block" do {:safe, result} = htm do - unquote(tag)() do - unquote(tag)() - end + unquote(tag)(do: unquote(tag)()) end assert result == ~s{<#{unquote(tag)}><#{unquote(tag)}>} @@ -58,7 +56,10 @@ defmodule Temple.TagsTest do end end - assert result == ~s{<#{unquote(tag)} class="hello"><#{unquote(tag)}>} + assert result == + ~s{<#{unquote(tag)} class="hello"><#{unquote(tag)}>} end end diff --git a/test/temple_test.exs b/test/temple_test.exs index 16303a0..f823b4b 100644 --- a/test/temple_test.exs +++ b/test/temple_test.exs @@ -160,6 +160,7 @@ defmodule TempleTest do variable_as_prop_with_block props do div() end + variable_as_prop_with_block %{bob: "hi"} do div() end