Skip to content

Commit

Permalink
Merge pull request #268 from kawoou/master
Browse files Browse the repository at this point in the history
Support swift 5.0
  • Loading branch information
djbe authored May 23, 2019
2 parents 6addc46 + 4020a98 commit e516ca9
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 11 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,24 @@ matrix:
- os: osx
osx_image: xcode10
env: SWIFT_VERSION=4.2
- os: osx
osx_image: xcode10.2
env: SWIFT_VERSION=5.0
- os: linux
env: SWIFT_VERSION=4.0.3
- os: linux
env: SWIFT_VERSION=4.1
- os: linux
env: SWIFT_VERSION=4.2
- os: linux
env: SWIFT_VERSION=4.2.3
- os: linux
env: SWIFT_VERSION=5.0
language: generic
sudo: required
dist: trusty
install:
- eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"; fi
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then wget --output-document /tmp/SwiftLint.pkg https://github.com/realm/SwiftLint/releases/download/0.27.0/SwiftLint.pkg &&
sudo installer -pkg /tmp/SwiftLint.pkg -target /; fi
script:
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/kylef/PathKit.git",
"state": {
"branch": null,
"revision": "e2f5be30e4c8f531c9c1e8765aa7b71c0a45d7a0",
"version": "0.9.2"
"revision": "73f8e9dca9b7a3078cb79128217dc8f2e585a511",
"version": "1.0.0"
}
},
{
Expand Down
23 changes: 23 additions & 0 deletions Package@swift-5.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// swift-tools-version:5.0
import PackageDescription

let package = Package(
name: "Stencil",
products: [
.library(name: "Stencil", targets: ["Stencil"])
],
dependencies: [
.package(url: "https://github.com/kylef/PathKit.git", from: "1.0.0"),
.package(url: "https://github.com/kylef/Spectre.git", from: "0.9.0")
],
targets: [
.target(name: "Stencil", dependencies: [
"PathKit"
], path: "Sources"),
.testTarget(name: "StencilTests", dependencies: [
"Stencil",
"Spectre"
])
],
swiftLanguageVersions: [.v4, .v4_2, .v5]
)
2 changes: 1 addition & 1 deletion Sources/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class VariableNode: NodeType {

if hasToken("if", at: 1) {
let components = components.suffix(from: 2)
if let elseIndex = components.index(of: "else") {
if let elseIndex = components.firstIndex(of: "else") {
condition = try parser.compileExpression(components: Array(components.prefix(upTo: elseIndex)), token: token)
let elseToken = components.suffix(from: elseIndex.advanced(by: 1)).joined(separator: " ")
elseExpression = try parser.compileResolvable(elseToken, containedIn: token)
Expand Down
8 changes: 8 additions & 0 deletions Sources/_SwiftSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ public extension Variable {
}
}
#endif

#if !swift(>=4.2)
extension ArraySlice where Element: Equatable {
func firstIndex(of element: Element) -> Int? {
return index(of: element)
}
}
#endif
2 changes: 1 addition & 1 deletion Stencil.podspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"tvos": "9.0"
},
"cocoapods_version": ">= 1.4.0",
"swift_version": "4.2",
"swift_version": "5.0",
"requires_arc": true,
"dependencies": {
"PathKit": [
Expand Down
4 changes: 2 additions & 2 deletions Tests/StencilTests/EnvironmentSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ final class EnvironmentIncludeTemplateTests: XCTestCase {
override func setUp() {
super.setUp()

let path = Path(#file) + ".." + "fixtures"
let path = Path(#file as String) + ".." + "fixtures"
let loader = FileSystemLoader(paths: [path])
environment = Environment(loader: loader)
template = ""
Expand Down Expand Up @@ -291,7 +291,7 @@ final class EnvironmentBaseAndChildTemplateTests: XCTestCase {
override func setUp() {
super.setUp()

let path = Path(#file) + ".." + "fixtures"
let path = Path(#file as String) + ".." + "fixtures"
let loader = FileSystemLoader(paths: [path])
environment = Environment(loader: loader)
childTemplate = ""
Expand Down
2 changes: 1 addition & 1 deletion Tests/StencilTests/IncludeSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Spectre
import XCTest

final class IncludeTests: XCTestCase {
let path = Path(#file) + ".." + "fixtures"
let path = Path(#file as String) + ".." + "fixtures"
lazy var loader = FileSystemLoader(paths: [path])
lazy var environment = Environment(loader: loader)

Expand Down
2 changes: 1 addition & 1 deletion Tests/StencilTests/InheritanceSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Stencil
import XCTest

final class InheritanceTests: XCTestCase {
let path = Path(#file) + ".." + "fixtures"
let path = Path(#file as String) + ".." + "fixtures"
lazy var loader = FileSystemLoader(paths: [path])
lazy var environment = Environment(loader: loader)

Expand Down
2 changes: 1 addition & 1 deletion Tests/StencilTests/LexerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ final class LexerTests: XCTestCase {
}

func testPerformance() throws {
let path = Path(#file) + ".." + "fixtures" + "huge.html"
let path = Path(#file as String) + ".." + "fixtures" + "huge.html"
let content: String = try path.read()

measure {
Expand Down
2 changes: 1 addition & 1 deletion Tests/StencilTests/LoaderSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import XCTest

final class TemplateLoaderTests: XCTestCase {
func testFileSystemLoader() {
let path = Path(#file) + ".." + "fixtures"
let path = Path(#file as String) + ".." + "fixtures"
let loader = FileSystemLoader(paths: [path])
let environment = Environment(loader: loader)

Expand Down

0 comments on commit e516ca9

Please sign in to comment.