Skip to content

Commit

Permalink
Merge pull request #45 from siemensikkema/no-newline-after-loop
Browse files Browse the repository at this point in the history
Remove newline after loop
  • Loading branch information
loganwright authored Feb 13, 2017
2 parents d3a3db7 + 42f93a4 commit b0f6980
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/Leaf/Tag/Models/Loop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public final class Loop: Tag {
context.pop()
return rendered
}
return try array
.map(renderItem)
.flatMap { $0 + [.newLine] }
return try array.map(renderItem)
.joined(separator: [.newLine])
.flatMap { $0 }
}
}
2 changes: 1 addition & 1 deletion Tests/LeafTests/ContextTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ContextTests: XCTestCase {
let template = try stem.spawnLeaf(raw: raw)
let context = Context(["friends": ["a", "b", "c", "#loop"]])
let rendered = try stem.render(template, with: context).string
let expectation = "Hello, a!\nHello, b!\nHello, c!\nHello, #loop!\n"
let expectation = "Hello, a!\nHello, b!\nHello, c!\nHello, #loop!"
XCTAssert(rendered == expectation)
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/LeafTests/LoopTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoopTests: XCTestCase {
]
])
let loadable = Context(context)
let expectation = "Hello, asdf\nHello, 🐌\nHello, 8###z0-1\nHello, 12\n"
let expectation = "Hello, asdf\nHello, 🐌\nHello, 8###z0-1\nHello, 12"
let rendered = try stem.render(template, with: loadable).string
XCTAssert(rendered == expectation, "have: \(rendered), want: \(expectation)")
}
Expand All @@ -51,7 +51,7 @@ class LoopTests: XCTestCase {
let template = try stem.spawnLeaf(named: "complex-loop")
let loadable = Context(context)
let rendered = try stem.render(template, with: loadable).string
let expectation = "<li><b>Venus</b>: 12345</li>\n<li><b>Pluto</b>: 888</li>\n<li><b>Mercury</b>: 9000</li>\n"
let expectation = "<li><b>Venus</b>: 12345</li>\n<li><b>Pluto</b>: 888</li>\n<li><b>Mercury</b>: 9000</li>"
XCTAssert(rendered == expectation, "have: \(rendered) want: \(expectation)")
}

Expand Down Expand Up @@ -94,6 +94,6 @@ class LoopTests: XCTestCase {
let leaf = try stem.spawnLeaf(raw: "#loop(names, \"name\") { Hello, #(name)! }")
let context = Context(["names": "Rick"])
let rendered = try stem.render(leaf, with: context).string
XCTAssert(rendered == "Hello, Rick!\n")
XCTAssert(rendered == "Hello, Rick!")
}
}

0 comments on commit b0f6980

Please sign in to comment.