Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Textarea adds blank lines #48

Closed
henrik opened this issue Oct 10, 2015 · 5 comments · Fixed by #53
Closed

Textarea adds blank lines #48

henrik opened this issue Oct 10, 2015 · 5 comments · Fixed by #53

Comments

@henrik
Copy link
Contributor

henrik commented Oct 10, 2015

When I upgrade a project from slim_fast 0.7.0 to 0.9.1, the Slim code

textarea id="code" name="code" = "foo"

that previously on 0.7.0 would output

<textarea id="code" name="code">foo</textarea>

now on 0.9.1 outputs

<textarea id="code" name="code">foo
</textarea>

This leads to extra linebreaks in the received input, that were not intended.

@henrik
Copy link
Contributor Author

henrik commented Oct 10, 2015

Looking into this myself. Happens with textarea = "foo" but not textarea foo

@henrik
Copy link
Contributor Author

henrik commented Oct 10, 2015

Failing test:

  test "does not add linebreaks to textarea with '=' output" do
    slim = ~s"""
    textarea = "foo"
    """

    assert render(slim) == ~s(<textarea>foo</textarea>)
  end

Will see if I can figure out how to fix it, too, but I suspect that's trickier.

@henrik
Copy link
Contributor Author

henrik commented Oct 10, 2015

This change will fix my test but break a bunch of others:

--- a/lib/slim_fast/compiler.ex
+++ b/lib/slim_fast/compiler.ex
@@ -43,7 +43,7 @@ defmodule SlimFast.Compiler do

   defp open(_, %{type: :eex, content: code, attributes: attrs}) do
     inline = if attrs[:inline], do: "=", else: ""
-    "<%#{inline} #{code} %>\n"
+    "<%#{inline} #{code} %>"
   end

Don't want to wrap my head around this now, so I think I'll leave it at that :)

@henrik
Copy link
Contributor Author

henrik commented Oct 10, 2015

I don't completely understand why those newlines are being added. They're also added e.g. inside <title> which seems weird. So the simplest fix would just be to not add those newlines anywhere, but I guess there's some reason they were introduced?

If the newlines should remain, I did figure out how to skip them for textareas only, though it's not super pretty: henrik@2de86b3

@doomspork
Copy link
Member

Hey @henrik! I haven't had a chance to look into this yet but I suspect this PR is to blame for the newlines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants