Skip to content

Commit

Permalink
Merge pull request #46 from vapor/alpha
Browse files Browse the repository at this point in the history
update dependencies
  • Loading branch information
loganwright authored Feb 16, 2017
2 parents b0f6980 + 37bdf88 commit 9fffbb4
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PackageDescription
let package = Package(
name: "Leaf",
dependencies: [
.Package(url: "https://github.com/vapor/core.git", majorVersion: 1),
.Package(url: "https://github.com/vapor/node.git", majorVersion: 1)
.Package(url: "https://github.com/vapor/core.git", Version(2,0,0, prereleaseIdentifiers: ["alpha"])),
.Package(url: "https://github.com/vapor/node.git", Version(2,0,0, prereleaseIdentifiers: ["alpha"]))
]
)
10 changes: 5 additions & 5 deletions Sources/Leaf/Buffer/Buffer+Leaf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension BufferProtocol where Element == Byte {

// check if body
moveForward()
guard current == .space, next == .openCurly else {
guard current == .space, next == .leftCurlyBracket else {
return TagTemplate(name: name, parameters: parameters, body: Leaf?.none)
}
moveForward() // queue up `{`
Expand All @@ -91,20 +91,20 @@ extension BufferProtocol where Element == Byte {

mutating func extractInstructionName() throws -> String {
moveForward() // drop initial token from name. a secondary token implies chain
let name = extractUntil { $0 == .openParenthesis }
guard current == .openParenthesis else {
let name = extractUntil { $0 == .leftParenthesis }
guard current == .leftParenthesis else {
throw ParseError.expectedOpenParenthesis
}
return name.string
}

mutating func extractInstructionParameters() throws -> [Parameter] {
return try extractSection(opensWith: .openParenthesis, closesWith: .closedParenthesis)
return try extractSection(opensWith: .leftParenthesis, closesWith: .rightParenthesis)
.extractParameters()
}

mutating func extractBody() throws -> String {
return try extractSection(opensWith: .openCurly, closesWith: .closedCurly)
return try extractSection(opensWith: .leftCurlyBracket, closesWith: .rightCurlyBracket)
.trimmed(.whitespace)
.string
}
Expand Down
11 changes: 0 additions & 11 deletions Sources/Leaf/Byte+Leaf.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
// TODO: => Core
extension Byte {
public static let openParenthesis = "(".bytes.first!
public static let closedParenthesis = ")".bytes.first!

public static let openCurly = "{".bytes.first!
public static let closedCurly = "}".bytes.first!

public static let quotationMark = "\"".bytes.first!
}

extension Sequence where Iterator.Element == Byte {
public static var whitespace: Bytes {
return [ .space, .newLine, .carriageReturn, .horizontalTab]
Expand Down
14 changes: 7 additions & 7 deletions Sources/Leaf/HTMLEscape.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ extension String {
.replacingOccurrences(of: "<", with: "&lt;")
.replacingOccurrences(of: ">", with: "&gt;")
*/
return bytes
return makeBytes()
.split(separator: .ampersand, omittingEmptySubsequences: false)
.joined(separator: "&amp;".bytes)
.split(separator: .quotationMark, omittingEmptySubsequences: false)
.joined(separator: "&quot;".bytes)
.joined(separator: "&amp;".makeBytes())
.split(separator: .quote, omittingEmptySubsequences: false)
.joined(separator: "&quot;".makeBytes())
.split(separator: .apostrophe, omittingEmptySubsequences: false)
.joined(separator: "&#39;".bytes)
.joined(separator: "&#39;".makeBytes())
.split(separator: .lessThan, omittingEmptySubsequences: false)
.joined(separator: "&lt;".bytes)
.joined(separator: "&lt;".makeBytes())
.split(separator: .greaterThan, omittingEmptySubsequences: false)
.joined(separator: "&gt;".bytes)
.joined(separator: "&gt;".makeBytes())
.string
}
}
8 changes: 5 additions & 3 deletions Sources/Leaf/Node+Rendered.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ extension Node {
case .array(_), .object(_), .null:
return []
case let .bool(bool):
return bool.description.bytes
return bool.description.makeBytes()
case let .number(number):
return number.description.bytes
return number.description.makeBytes()
case let .string(str):
// defaults to escaping, use #raw(var) to unescape.
return str.htmlEscaped().bytes
return str.htmlEscaped().makeBytes()
case let .bytes(bytes):
return bytes
case let .date(date):
return Date.outgoingDateFormatter.string(from: date).makeBytes()
}
}
}
2 changes: 1 addition & 1 deletion Sources/Leaf/Parameter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Parameter {
internal init<S: Sequence>(_ bytes: S) throws where S.Iterator.Element == Byte {
let bytes = bytes.array.trimmed(.whitespace)
guard !bytes.isEmpty else { throw Error.nonEmptyArgumentRequired }
if bytes.count > 1, bytes.first == .quotationMark, bytes.last == .quotationMark {
if bytes.count > 1, bytes.first == .quote, bytes.last == .quote {
self = .constant(value: bytes.dropFirst().dropLast().string)
} else {
let path = bytes.split(
Expand Down
2 changes: 1 addition & 1 deletion Sources/Leaf/Stem+Render.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extension Stem {
context: Context,
value: Node?,
tagTemplate: TagTemplate) throws -> Bytes {
// return "World".bytes
// return "World".makeBytes()
if let subLeaf = tagTemplate.body {
if let val = value { context.push(["self": val]) }
return try tag.render(stem: self, context: context, value: value, leaf: subLeaf)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Leaf/Stem+Spawn.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extension Stem {
public func spawnLeaf(raw: String) throws -> Leaf {
return try spawnLeaf(raw: raw.bytes)
return try spawnLeaf(raw: raw.makeBytes())
}

public func spawnLeaf(raw: Bytes) throws -> Leaf {
Expand Down
4 changes: 4 additions & 0 deletions Sources/Leaf/Tag/Models/Equal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ fileprivate func fuzzyEquals(_ lhs: Node?, _ rhs: Node?) -> Bool {
return true
case let .string(string):
return string == rhs.string
case let .date(date):
// FIXME: Add fuzzy date access and equality?
guard case let .date(right) = rhs else { return false }
return date == right
}
}
4 changes: 2 additions & 2 deletions Sources/Leaf/Tag/Models/Raw.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ final class Raw: Tag {
let name = "raw"

func compileBody(stem: Stem, raw: String) throws -> Leaf {
let component = Leaf.Component.raw(raw.bytes)
let component = Leaf.Component.raw(raw.makeBytes())
return Leaf(raw: raw, components: [component])
}

func run(stem: Stem, context: Context, tagTemplate: TagTemplate, arguments: [Argument]) throws -> Node? {
guard let string = arguments.first?.value?.string else { return nil }
let unescaped = string.bytes
let unescaped = string.makeBytes()
return .bytes(unescaped)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Leaf/Tag/TagTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ public final class TagTemplate {
internal init(name: String, parameters: [Parameter], body: Leaf?) {
// we strip leading token, if another one is there,
// that means we've found a chain element, ie: @@else {
if name.bytes.first == TOKEN {
if name.makeBytes().first == TOKEN {
self.isChain = true
self.name = name.bytes.dropFirst().string
self.name = name.makeBytes().dropFirst().string
} else {
self.isChain = false
self.name = name
Expand Down
4 changes: 2 additions & 2 deletions Tests/LeafTests/BufferTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ class BufferTests: XCTestCase {
]

func testSectionOpenerThrow() throws {
var buffer = Buffer("No opener".bytes)
var buffer = Buffer("No opener".makeBytes())
do {
_ = try buffer.extractSection(opensWith: .period, closesWith: .period)
XCTFail()
} catch ParseError.missingBodyOpener {}
}

func testSectionCloserThrow() throws {
var buffer = Buffer(". No closer".bytes)
var buffer = Buffer(". No closer".makeBytes())
do {
_ = try buffer.extractSection(opensWith: .period, closesWith: .period)
XCTFail()
Expand Down
16 changes: 8 additions & 8 deletions Tests/LeafTests/NodeRenderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ class NodeRenderTests: XCTestCase {

func testRender() throws {
var node = Node("Hello")
XCTAssert(try node.rendered() == "Hello".bytes)
XCTAssert(try node.rendered() == "Hello".makeBytes())

node = .bytes("SomeBytes".bytes)
XCTAssert(try node.rendered() == "SomeBytes".bytes)
node = .bytes("SomeBytes".makeBytes())
XCTAssert(try node.rendered() == "SomeBytes".makeBytes())

node = .number(19972)
XCTAssert(try node.rendered() == "19972".bytes)
XCTAssert(try node.rendered() == "19972".makeBytes())
node = .number(-98172)
XCTAssert(try node.rendered() == "-98172".bytes)
XCTAssert(try node.rendered() == "-98172".makeBytes())
node = .number(73.655)
XCTAssert(try node.rendered() == "73.655".bytes)
XCTAssert(try node.rendered() == "73.655".makeBytes())

node = .object([:])
XCTAssert(try node.rendered() == [])
Expand All @@ -29,8 +29,8 @@ class NodeRenderTests: XCTestCase {
XCTAssert(try node.rendered() == [])

node = .bool(true)
XCTAssert(try node.rendered() == "true".bytes)
XCTAssert(try node.rendered() == "true".makeBytes())
node = .bool(false)
XCTAssert(try node.rendered() == "false".bytes)
XCTAssert(try node.rendered() == "false".makeBytes())
}
}
4 changes: 2 additions & 2 deletions Tests/LeafTests/PerformanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PerformanceTests: XCTestCase {

func testLeaf() throws {
let raw = "Hello, #(name)!"
let expectation = "Hello, World!".bytes
let expectation = "Hello, World!".makeBytes()
let template = try stem.spawnLeaf(raw: raw)
let ctxt = Context(["name": "World"])
measure {
Expand Down Expand Up @@ -44,7 +44,7 @@ class PerformanceTests: XCTestCase {

func testLeafLong() throws {
let raw = [String](repeating: "Hello, #(name)!", count: 1000).joined(separator: ", ")
let expectation = [String](repeating: "Hello, World!", count: 1000).joined(separator: ", ").bytes
let expectation = [String](repeating: "Hello, World!", count: 1000).joined(separator: ", ").makeBytes()
let template = try stem.spawnLeaf(raw: raw)
_ = template.description
let ctxt = Context(["name": "World"])
Expand Down
2 changes: 1 addition & 1 deletion Tests/LeafTests/TagTemplateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class TagTemplateTests: XCTestCase {
}

func testEquatableComponents() throws {
let lhs = Leaf.Component.raw("raw".bytes)
let lhs = Leaf.Component.raw("raw".makeBytes())
let rhs = Leaf.Component.chain([])
XCTAssertNotEqual(lhs, rhs)
}
Expand Down

0 comments on commit 9fffbb4

Please sign in to comment.