11 Commits
0.5.0 ... 0.5.2

Author SHA1 Message Date
Kyle Fuller
19d712b4a4 Release 0.5.2 2016-01-30 14:57:26 +01:00
Kyle Fuller
201b8e263c Fix failing for node tests
These we're broken in commit 0783506
2015-12-14 16:03:48 +00:00
Kyle Fuller
03928721c4 Move away from deprecated curry syntax 2015-12-14 09:04:18 -05:00
Kyle Fuller
07835063ed Fix an ambiguous array literal warning 2015-12-14 09:04:01 -05:00
Kyle Fuller
3c13d81b21 Whoops, Tests not Specs 2015-12-09 19:20:05 +00:00
Kyle Fuller
1668830d9b [for] Provide forloop context, first, last and counter 2015-12-09 19:18:16 +00:00
Kyle Fuller
14195b3199 Include missing specs 2015-12-09 19:18:08 +00:00
Kyle Fuller
ae75ea5911 [podspec] Correct PathKit dependency 2015-12-09 19:16:47 +00:00
Kyle Fuller
9c9ebbe559 Release 0.5.1 2015-12-08 18:08:44 +00:00
Kyle Fuller
5cdf1d326b Merge pull request #47 from neonichu/fix-manifest
Needs to depend on PathKit 0.6.x
2015-12-08 16:32:39 +00:00
Boris Bügling
f78562a1fd Needs to depend on PathKit 0.6.x
Seems like this is a bug in the current "stable" SPM which has been
fixed upstream in the meantime.
2015-12-08 17:31:12 +01:00
5 changed files with 42 additions and 15 deletions

View File

@@ -3,6 +3,6 @@ import PackageDescription
let package = Package(
name: "Stencil",
dependencies: [
.Package(url: "https://github.com/kylef/PathKit.git", majorVersion: 0, minor: 5),
.Package(url: "https://github.com/kylef/PathKit.git", majorVersion: 0, minor: 6),
]
)

View File

@@ -158,8 +158,15 @@ public class ForNode : NodeType {
let values = try variable.resolve(context)
if let values = values as? [Any] where values.count > 0 {
return try values.map { item in
try context.push([loopVariable: item]) {
let count = values.count
return try values.enumerate().map { index, item in
let forContext: [String: Any] = [
"first": index == 0,
"last": index == (count - 1),
"counter": index + 1,
]
return try context.push([loopVariable: item, "forloop": forContext]) {
try renderNodes(nodes, context)
}
}.joinWithSeparator("")

View File

@@ -1,13 +1,15 @@
public func until(tags:[String])(parser:TokenParser, token:Token) -> Bool {
if let name = token.components().first {
for tag in tags {
if name == tag {
return true
public func until(tags: [String]) -> ((TokenParser, Token) -> Bool) {
return { parser, token in
if let name = token.components().first {
for tag in tags {
if name == tag {
return true
}
}
}
}
return false
return false
}
}
public typealias Filter = Any? throws -> Any?

View File

@@ -1,6 +1,6 @@
{
"name": "Stencil",
"version": "0.4.0",
"version": "0.5.2",
"summary": "Stencil is a simple and powerful template language for Swift.",
"homepage": "https://github.com/kylef/Stencil",
"license": {
@@ -8,12 +8,12 @@
"file": "LICENSE"
},
"authors": {
"Kyle Fuller": "inbox@kylefuller.co.uk"
"Kyle Fuller": "kyle@fuller.li"
},
"social_media_url": "http://twitter.com/kylefuller",
"source": {
"git": "https://github.com/kylef/Stencil.git",
"tag": "0.4.0"
"tag": "0.5.2"
},
"source_files": [
"Sources/*.swift"
@@ -24,7 +24,7 @@
},
"requires_arc": true,
"dependencies": {
"PathKit": [ "~> 0.5.0" ]
"PathKit": [ "~> 0.6.0" ]
},
"test_specification": {
"source_files": [
@@ -34,7 +34,7 @@
],
"dependencies": {
"Spectre": [ "~> 0.5.0" ],
"PathKit": [ "~> 0.5.0" ]
"PathKit": [ "~> 0.6.0" ]
}
}
}

View File

@@ -41,4 +41,22 @@ describe("ForNode") {
let node = ForNode(variable: "items", loopVariable: "item", nodes: nodes, emptyNodes: [])
try expect(try node.render(nsarray_context)) == "123"
}
$0.it("renders the given nodes while providing if the item is first in the context") {
let nodes: [NodeType] = [VariableNode(variable: "item"), VariableNode(variable: "forloop.first")]
let node = ForNode(variable: "items", loopVariable: "item", nodes: nodes, emptyNodes: [])
try expect(try node.render(context)) == "1true2false3false"
}
$0.it("renders the given nodes while providing if the item is last in the context") {
let nodes: [NodeType] = [VariableNode(variable: "item"), VariableNode(variable: "forloop.last")]
let node = ForNode(variable: "items", loopVariable: "item", nodes: nodes, emptyNodes: [])
try expect(try node.render(context)) == "1false2false3true"
}
$0.it("renders the given nodes while providing item counter") {
let nodes: [NodeType] = [VariableNode(variable: "item"), VariableNode(variable: "forloop.counter")]
let node = ForNode(variable: "items", loopVariable: "item", nodes: nodes, emptyNodes: [])
try expect(try node.render(context)) == "112233"
}
}