3 Commits
0.7.0 ... 0.7.2

Author SHA1 Message Date
Kyle Fuller
974b9c85a0 feat(template): Restore open state 2016-12-01 18:41:25 +00:00
Kyle Fuller
abae80d39d chore: Release 0.7.1 2016-11-30 17:13:29 +00:00
Kyle Fuller
d024da5567 fix(if): Allow operator use 2016-11-30 17:12:41 +00:00
5 changed files with 40 additions and 7 deletions

View File

@@ -1,5 +1,19 @@
# Stencil Changelog
## 0.7.2
### Enhancements
- `Template` is now an `open` class.
## 0.7.1
### Bug Fixes
- Fixes an issue where using `{% if %}` statements which use operators would
throw a syntax error.
## 0.7.0
### Breaking

View File

@@ -167,9 +167,6 @@ class IfNode : NodeType {
class func parse(_ parser: TokenParser, token: Token) throws -> NodeType {
var components = token.components()
guard components.count == 2 else {
throw TemplateSyntaxError("'if' statements should use the following 'if condition' `\(token.contents)`.")
}
components.removeFirst()
var trueNodes = [NodeType]()
var falseNodes = [NodeType]()

View File

@@ -6,7 +6,7 @@ let NSFileNoSuchFileError = 4
#endif
/// A class representing a template
public class Template: ExpressibleByStringLiteral {
open class Template: ExpressibleByStringLiteral {
let tokens: [Token]
/// Create a template with a template string
@@ -51,7 +51,7 @@ public class Template: ExpressibleByStringLiteral {
}
/// Render the given template
public func render(_ context: Context? = nil) throws -> String {
open func render(_ context: Context? = nil) throws -> String {
let context = context ?? Context()
let parser = TokenParser(tokens: tokens, namespace: context.namespace)
let nodes = try parser.parse()

View File

@@ -1,6 +1,6 @@
{
"name": "Stencil",
"version": "0.7.0",
"version": "0.7.2",
"summary": "Stencil is a simple and powerful template language for Swift.",
"homepage": "https://stencil.fuller.li",
"license": {
@@ -13,7 +13,7 @@
"social_media_url": "https://twitter.com/kylefuller",
"source": {
"git": "https://github.com/kylef/Stencil.git",
"tag": "0.6.0"
"tag": "0.7.2"
},
"source_files": [
"Sources/*.swift"

View File

@@ -27,6 +27,28 @@ func testIfNode() {
try expect(falseNode?.text) == "false"
}
$0.it("can parse an if with complex expression") {
let tokens: [Token] = [
.block(value: "if value == \"test\" and not name"),
.text(value: "true"),
.block(value: "else"),
.text(value: "false"),
.block(value: "endif")
]
let parser = TokenParser(tokens: tokens, namespace: Namespace())
let nodes = try parser.parse()
let node = nodes.first as? IfNode
let trueNode = node?.trueNodes.first as? TextNode
let falseNode = node?.falseNodes.first as? TextNode
try expect(nodes.count) == 1
try expect(node?.trueNodes.count) == 1
try expect(trueNode?.text) == "true"
try expect(node?.falseNodes.count) == 1
try expect(falseNode?.text) == "false"
}
$0.it("can parse an ifnot block") {
let tokens: [Token] = [
.block(value: "ifnot value"),