Repository: mhanberg/temple (elixir)

Issue:
Self closing tags cause compile error
**Describe the bug**
add `hr`, `input` or other self-closing tags in any html.exs files will cause compile error

**To Reproduce**
Steps to reproduce the behavior:
1. Go to `temple/integration_test/temple_demo/app.html.exs`
2. Add `hr` 
3. See error


```
Compiling 22 files (.ex)

== Compilation error in file lib/temple_demo_web/views/layout_view.ex ==
** (MatchError) no match of right hand side value: {[], []}
    (temple 0.6.1) lib/temple/parser/void_elements_aliases.ex:16: Temple.Parser.VoidElementsAliases.run/1
    (temple 0.6.1) lib/temple/parser.ex:132: Temple.Parser.parse/1
    (elixir 1.12.1) lib/enum.ex:3865: Enum.flat_map_list/2
    (elixir 1.12.1) lib/enum.ex:3866: Enum.flat_map_list/2
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:26: Temple.Parser.NonvoidElementsAliases.run/1
    (temple 0.6.1) lib/temple/parser.ex:132: Temple.Parser.parse/1
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:26: Temple.Parser.NonvoidElementsAliases.run/1
    (temple 0.6.1) lib/temple/parser.ex:132: Temple.Parser.parse/1
    (elixir 1.12.1) lib/enum.ex:3865: Enum.flat_map_list/2
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:26: Temple.Parser.NonvoidElementsAliases.run/1
    (temple 0.6.1) lib/temple/parser.ex:132: Temple.Parser.parse/1
    (elixir 1.12.1) lib/enum.ex:3865: Enum.flat_map_list/2
    (elixir 1.12.1) lib/enum.ex:3866: Enum.flat_map_list/2
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:26: Temple.Parser.NonvoidElementsAliases.run/1
    (temple 0.6.1) lib/temple/parser.ex:132: Temple.Parser.parse/1
    (temple 0.6.1) lib/temple/engine.ex:41: Temple.Engine.compile/2
    (phoenix 1.5.8) lib/phoenix/template.ex:351: Phoenix.Template.compile/3
    (phoenix 1.5.8) lib/phoenix/template.ex:166: anonymous fn/4 in Phoenix.Template."MACRO-__before_compile__"/2
    (elixir 1.12.1) lib/enum.ex:2356: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix 1.5.8) expanding macro: Phoenix.Template.__before_compile__/1
```


If I add attributes by Map type will cause another error.
```
attrs = %{
  id: "hr"
}
hr attrs
```

Error message:

```
Compiling 1 file (.ex)

== Compilation error in file lib/temple_demo_web/views/layout_view.ex ==
** (FunctionClauseError) no function clause matching in Temple.Parser.Utils.compile_attrs/1

    The following arguments were given to Temple.Parser.Utils.compile_attrs/1:

        # 1
        {:attrs, [line: 44], nil}

    Attempted function clauses (showing 3 out of 3):

        def compile_attrs([])
        def compile_attrs([attrs]) when is_list(attrs)
        def compile_attrs(attrs) when is_list(attrs)

    (temple 0.6.1) lib/temple/parser/utils.ex:10: Temple.Parser.Utils.compile_attrs/1
    (temple 0.6.1) lib/temple/parser/void_elements_aliases.ex:28: Temple.Generator.Temple.Parser.VoidElementsAliases.to_eex/1
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:38: anonymous fn/2 in Temple.Generator.Temple.Parser.NonvoidElementsAliases.to_eex/1
    (elixir 1.12.1) lib/enum.ex:2356: Enum."-reduce/3-lists^foldl/2-0-"/3
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:38: Temple.Generator.Temple.Parser.NonvoidElementsAliases.to_eex/1
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:38: anonymous fn/2 in Temple.Generator.Temple.Parser.NonvoidElementsAliases.to_eex/1
    (elixir 1.12.1) lib/enum.ex:2356: Enum."-reduce/3-lists^foldl/2-0-"/3
    (temple 0.6.1) lib/temple/parser/nonvoid_elements_aliases.ex:38: Temple.Generator.Temple.Parser.NonvoidElementsAliases.to_eex/1
    (elixir 1.12.1) lib/enum.ex:1553: Enum."-map/2-lists^map/1-0-"/2
    (temple 0.6.1) lib/temple/engine.ex:41: Temple.Engine.compile/2
    (phoenix 1.5.8) lib/phoenix/template.ex:351: Phoenix.Template.compile/3
    (phoenix 1.5.8) lib/phoenix/template.ex:166: anonymous fn/4 in Phoenix.Template."MACRO-__before_compile__"/2
    (elixir 1.12.1) lib/enum.ex:2356: Enum."-reduce/3-lists^foldl/2-0-"/3
    (phoenix 1.5.8) expanding macro: Phoenix.Template.__before_compile__/1
    lib/temple_demo_web/views/layout_view.ex:1: TempleDemoWeb.LayoutView (module)
```


It works find when just type `hr id: "hr"`.




Pull request:
Void elements can be compiled with no attrs
Fixes #134


Patch:
diff --git a/lib/temple/parser/nonvoid_elements_aliases.ex b/lib/temple/parser/nonvoid_elements_aliases.ex
index a60e9cb..89cb09d 100644
--- a/lib/temple/parser/nonvoid_elements_aliases.ex
+++ b/lib/temple/parser/nonvoid_elements_aliases.ex
@@ -17,9 +17,7 @@ defmodule Temple.Parser.NonvoidElementsAliases do
   def run({name, _, args}) do
     name = Parser.nonvoid_elements_lookup()[name]
 
-    {do_and_else, args} =
-      args
-      |> Temple.Parser.Utils.split_args()
+    {do_and_else, args} = Temple.Parser.Utils.split_args(args)
 
     {do_and_else, args} = Temple.Parser.Utils.consolidate_blocks(do_and_else, args)
 
diff --git a/lib/temple/parser/void_elements_aliases.ex b/lib/temple/parser/void_elements_aliases.ex
index c1f9292..7abd6b9 100644
--- a/lib/temple/parser/void_elements_aliases.ex
+++ b/lib/temple/parser/void_elements_aliases.ex
@@ -13,7 +13,14 @@ defmodule Temple.Parser.VoidElementsAliases do
 
   @impl Temple.Parser
   def run({name, _, args}) do
-    {_do_and_else, [args]} = Temple.Parser.Utils.split_args(args)
+    args =
+      case Temple.Parser.Utils.split_args(args) do
+        {_, [args]} when is_list(args) ->
+          args
+
+        {_, args} ->
+          args
+      end
 
     name = Temple.Parser.void_elements_lookup()[name]
 


Test patch:
diff --git a/test/temple_test.exs b/test/temple_test.exs
index a72b698..fe9339c 100644
--- a/test/temple_test.exs
+++ b/test/temple_test.exs
@@ -317,4 +317,22 @@ defmodule TempleTest do
     assert result ==
              ~s{<fieldset<%= Temple.Parser.Utils.runtime_attrs(Foo.foo_bar()) %>><input type="text"></fieldset>}
   end
+
+  test "hr tag works" do
+    assigns = %{foo: [class: "foofoo"]}
+
+    result =
+      temple do
+        div do: "foo"
+        hr()
+        div do: "foo"
+        hr @foo
+        div do: "bar"
+        hr class: "foofoo"
+        div do: "bar"
+      end
+
+    assert evaluate_template(result, assigns) ==
+             ~s{<div>foo</div><hr><div>foo</div><hr class="foofoo"><div>bar</div><hr class="foofoo"><div>bar</div>}
+  end
 end