diff --git a/lib/ex_cell/base.ex b/lib/ex_cell/base.ex index c05009b..5fc5101 100644 --- a/lib/ex_cell/base.ex +++ b/lib/ex_cell/base.ex @@ -29,7 +29,7 @@ defmodule ExCell.Base do def data_attribute(name, data, params) when is_list(data) do data - |> Keyword.merge([cell: name, cell_params: Poison.encode!(params)]) + |> Keyword.merge(cell: name, cell_params: Poison.encode!(params)) end def class_attribute(name, class) do @@ -159,6 +159,7 @@ defmodule ExCell.Base do defp do_container(params, options, content) do {tag, options} = Keyword.pop(options, :tag, :div) + {closing_tag, options} = Keyword.pop(options, :closing_tag, true) attributes = attributes( attribute_name(), @@ -167,8 +168,8 @@ defmodule ExCell.Base do params(params) ) - case content do - nil -> Tag.tag(tag, attributes) + case closing_tag do + false -> Tag.tag(tag, attributes) _ -> Tag.content_tag(tag, content, attributes) end end diff --git a/test/ex_cell/cell_test.exs b/test/ex_cell/cell_test.exs index b1b183d..4810e13 100644 --- a/test/ex_cell/cell_test.exs +++ b/test/ex_cell/cell_test.exs @@ -38,17 +38,17 @@ defmodule ExCell.CellTest do describe "container/3" do test "defaults to a :div as tag" do assert safe_to_string(MockCell.container()) - == "
" + == "
" end test "overrideables" do assert safe_to_string(MockCellWithOverridables.container()) - == "
" + == "
" end test "custom tag" do assert safe_to_string(MockCell.container(%{}, tag: :p)) - == "

" + == "

" end test "content" do @@ -65,18 +65,24 @@ defmodule ExCell.CellTest do test "cell params" do assert safe_to_string( MockCell.container(%{ foo: "bar" }) - ) == "
" + ) == "
" end test "attributes" do assert safe_to_string( MockCell.container(%{}, foo: "bar") - ) == "
" + ) == "
" end test "data attributes" do assert safe_to_string( MockCell.container(%{}, data: [foo: "bar"]) + ) == "
" + end + + test "no closing tag" do + assert safe_to_string( + MockCell.container(%{}, closing_tag: false, data: [foo: "bar"]) ) == "
" end end