Skip to content

Commit

Permalink
move line spacing insertion into a separate func
Browse files Browse the repository at this point in the history
  • Loading branch information
little-bobby-tables authored and Rakoth committed May 23, 2017
1 parent aa5f1d7 commit 0209bdd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/slime/parser/text_block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@ defmodule Slime.Parser.TextBlock do
text_indent = Enum.find_value(lines, 0,
fn({indent, line, _}) -> line != "" && indent end)

{text, is_eex} = Enum.reduce(lines, {"", false},
fn ({line_indent, line, is_eex_line}, {text, is_eex}) ->
text = if text == "", do: text, else: text <> "\n"
leading_space = String.duplicate(" ", line_indent - text_indent)
{text <> leading_space <> line, is_eex || is_eex_line}
end)
{text, is_eex} = insert_line_spacing(lines, text_indent)

text = text <> trailing_whitespace

Expand All @@ -42,4 +37,13 @@ defmodule Slime.Parser.TextBlock do
text
end
end

defp insert_line_spacing(lines, text_indent) do
lines |> Enum.reduce({"", false},
fn ({line_indent, line, is_eex_line}, {text, is_eex}) ->
text = if text == "", do: text, else: text <> "\n"
leading_space = String.duplicate(" ", line_indent - text_indent)
{text <> leading_space <> line, is_eex || is_eex_line}
end)
end
end

0 comments on commit 0209bdd

Please sign in to comment.