Skip to content

Commit

Permalink
Wrap all attributes values into quotes
Browse files Browse the repository at this point in the history
resolve #23
  • Loading branch information
Rakoth committed Aug 12, 2015
1 parent 3d6eca2 commit 4740a60
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 3 additions & 5 deletions lib/slim_fast/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ defmodule SlimFast.Compiler do
defp render_attribute(_, ""), do: ""
defp render_attribute(name, value) do
value = cond do
is_binary(value) ->
"\"" <> value <> "\""
is_list(value) ->
"\"" <> Enum.join(value, " ") <> "\""
is_binary(value) -> value
is_list(value) -> Enum.join(value, " ")
is_tuple(value) ->
{_, attrs} = value
"<%=" <> attrs[:content] <> "%>"
true -> to_string(value)
end

to_string(name) <> "=" <> value
~s(#{to_string(name)}="#{value}")
end

defp render_branch(%{type: :doctype, content: text}), do: text
Expand Down
2 changes: 1 addition & 1 deletion test/compiler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule CompilerTest do
children: [],
content: "Hello World"}]}]}]

expected = "<div id=<%=variable%> class=\"class\"><p>Hello World</p></div>"
expected = ~s(<div id="<%=variable%>" class="class"><p>Hello World</p></div>)
assert Compiler.compile(tree) == expected
end

Expand Down
9 changes: 9 additions & 0 deletions test/renderer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,13 @@ defmodule RendererTest do

assert render(slim) == "test"
end

test "render attributes specified by variable with spaces in value" do
slim = """
- style = "display: none"
div style=style
"""

assert render(slim) == ~s(<div style="display: none"></div>)
end
end

0 comments on commit 4740a60

Please sign in to comment.