0001    import Foundation
0002    
0003    public struct TemplateSyntaxError
Include.swift:11
      throw TemplateSyntaxError("'include' tag takes one argument, the template file to be included")
Include.swift:23
      throw TemplateSyntaxError("Template loader not in context")
Include.swift:27
      throw TemplateSyntaxError("'\(self.templateName)' could not be resolved as a string")
Include.swift:32
      throw TemplateSyntaxError("'\(templateName)' template not found in \(paths)")
Inheritence.swift:37
      throw TemplateSyntaxError("'extends' takes one argument, the template file to be extended")
Inheritence.swift:42
      throw TemplateSyntaxError("'extends' cannot appear more than once in the same template")
Inheritence.swift:64
      throw TemplateSyntaxError("Template loader not in context")
Inheritence.swift:68
      throw TemplateSyntaxError("'\(self.templateName)' could not be resolved as a string")
Inheritence.swift:73
      throw TemplateSyntaxError("'\(templateName)' template not found in \(paths)")
Inheritence.swift:93
      throw TemplateSyntaxError("'block' tag takes one argument, the template file to be included")
Node.swift:11
public func ==(lhs:TemplateSyntaxError, rhs:TemplateSyntaxError) -> Bool {
Node.swift:11
public func ==(lhs:TemplateSyntaxError, rhs:TemplateSyntaxError) -> Bool {
Node.swift:89
      throw TemplateSyntaxError("'now' tags may only have one argument: the format string `\(token.contents)`.")
Node.swift:132
      throw TemplateSyntaxError("'for' statements should use the following 'for x in y' `\(token.contents)`.")
Node.swift:143
      throw TemplateSyntaxError("`endfor` was not found.")
Node.swift:193
      throw TemplateSyntaxError("'if' statements should use the following 'if condition' `\(token.contents)`.")
Node.swift:202
      throw TemplateSyntaxError("`endif` was not found.")
Node.swift:216
      throw TemplateSyntaxError("'ifnot' statements should use the following 'if condition' `\(token.contents)`.")
Node.swift:225
      throw TemplateSyntaxError("`endif` was not found.")
Parser.swift:57
            throw TemplateSyntaxError("Unknown template tag '\(tag)'")
Parser.swift:85
    throw TemplateSyntaxError("Invalid filter '\(name)'")
Variable.swift:13
      throw TemplateSyntaxError("Variable tags must include at least 1 argument")
: ErrorType, Equatable, CustomStringConvertible { 0004 public let description
Node.swift:7
    self.description = description
Node.swift:12
  return lhs.description == rhs.description
Node.swift:12
  return lhs.description == rhs.description
:String 0005 0006 public init
Include.swift:11
      throw TemplateSyntaxError("'include' tag takes one argument, the template file to be included")
Include.swift:23
      throw TemplateSyntaxError("Template loader not in context")
Include.swift:27
      throw TemplateSyntaxError("'\(self.templateName)' could not be resolved as a string")
Inheritence.swift:37
      throw TemplateSyntaxError("'extends' takes one argument, the template file to be extended")
Inheritence.swift:42
      throw TemplateSyntaxError("'extends' cannot appear more than once in the same template")
Inheritence.swift:64
      throw TemplateSyntaxError("Template loader not in context")
Inheritence.swift:68
      throw TemplateSyntaxError("'\(self.templateName)' could not be resolved as a string")
Inheritence.swift:73
      throw TemplateSyntaxError("'\(templateName)' template not found in \(paths)")
Inheritence.swift:93
      throw TemplateSyntaxError("'block' tag takes one argument, the template file to be included")
Node.swift:89
      throw TemplateSyntaxError("'now' tags may only have one argument: the format string `\(token.contents)`.")
Node.swift:132
      throw TemplateSyntaxError("'for' statements should use the following 'for x in y' `\(token.contents)`.")
Node.swift:143
      throw TemplateSyntaxError("`endfor` was not found.")
Node.swift:193
      throw TemplateSyntaxError("'if' statements should use the following 'if condition' `\(token.contents)`.")
Node.swift:202
      throw TemplateSyntaxError("`endif` was not found.")
Node.swift:216
      throw TemplateSyntaxError("'ifnot' statements should use the following 'if condition' `\(token.contents)`.")
Node.swift:225
      throw TemplateSyntaxError("`endif` was not found.")
Parser.swift:57
            throw TemplateSyntaxError("Unknown template tag '\(tag)'")
Parser.swift:85
    throw TemplateSyntaxError("Invalid filter '\(name)'")
Variable.swift:13
      throw TemplateSyntaxError("Variable tags must include at least 1 argument")
(_ description:String) { 0007 self.description = description 0008 } 0009 } 0010 0011 public func ==(lhs:TemplateSyntaxError, rhs:TemplateSyntaxError) -> Bool { 0012 return lhs.description == rhs.description 0013 } 0014 0015 public protocol NodeType
Include.swift:4
public class IncludeNode : NodeType {
Include.swift:7
  public class func parse(parser: TokenParser, token: Token) throws -> NodeType {
Inheritence.swift:29
class ExtendsNode : NodeType {
Inheritence.swift:33
  class func parse(parser: TokenParser, token: Token) throws -> NodeType {
Inheritence.swift:47
    let nodes = blockNodes.reduce([String:BlockNode]()) { (accumulator, node:NodeType) -> [String:BlockNode] in
Inheritence.swift:85
class BlockNode : NodeType {
Inheritence.swift:87
  let nodes: [NodeType]
Inheritence.swift:89
  class func parse(parser: TokenParser, token: Token) throws -> NodeType {
Inheritence.swift:102
  init(name: String, nodes: [NodeType]) {
Namespace.swift:2
  public typealias TagParser = (TokenParser, Token) throws -> NodeType
Node.swift:21
public func renderNodes(nodes:[NodeType], _ context:Context) throws -> String {
Node.swift:25
public class SimpleNode : NodeType {
Node.swift:37
public class TextNode : NodeType {
Node.swift:53
public class VariableNode : NodeType {
Node.swift:81
public class NowNode : NodeType {
Node.swift:84
  public class func parse(parser:TokenParser, token:Token) throws -> NodeType {
Node.swift:122
public class ForNode : NodeType {
Node.swift:125
  let nodes:[NodeType]
Node.swift:126
  let emptyNodes: [NodeType]
Node.swift:128
  public class func parse(parser:TokenParser, token:Token) throws -> NodeType {
Node.swift:138
    var emptyNodes = [NodeType]()
Node.swift:154
  public init(variable:String, loopVariable:String, nodes:[NodeType], emptyNodes:[NodeType]) {
Node.swift:154
  public init(variable:String, loopVariable:String, nodes:[NodeType], emptyNodes:[NodeType]) {
Node.swift:185
public class IfNode : NodeType {
Node.swift:187
  public let trueNodes:[NodeType]
Node.swift:188
  public let falseNodes:[NodeType]
Node.swift:190
  public class func parse(parser:TokenParser, token:Token) throws -> NodeType {
Node.swift:196
    var trueNodes = [NodeType]()
Node.swift:197
    var falseNodes = [NodeType]()
Node.swift:213
  public class func parse_ifnot(parser:TokenParser, token:Token) throws -> NodeType {
Node.swift:219
    var trueNodes = [NodeType]()
Node.swift:220
    var falseNodes = [NodeType]()
Node.swift:236
  public init(variable:String, trueNodes:[NodeType], falseNodes:[NodeType]) {
Node.swift:236
  public init(variable:String, trueNodes:[NodeType], falseNodes:[NodeType]) {
Parser.swift:19
  public typealias TagParser = (TokenParser, Token) throws -> NodeType
Parser.swift:30
  public func parse() throws -> [NodeType] {
Parser.swift:34
  public func parse(parse_until:((parser:TokenParser, token:Token) -> (Bool))?) throws -> [NodeType] {
Parser.swift:35
    var nodes = [NodeType]()
{ 0016 /// Render the node in the given context 0017 func render
Node.swift:22
  return try nodes.map { try $0.render(context) }.joinWithSeparator("")
(context:Context) throws -> String 0018 } 0019 0020 /// Render the collection of nodes in the given context 0021 public func renderNodes
Inheritence.swift:112
    return try renderNodes(nodes, context)
Node.swift:174
          try renderNodes(nodes, context)
Node.swift:180
      try renderNodes(emptyNodes, context)
Node.swift:257
      output = try renderNodes(trueNodes, context)
Node.swift:259
      output = try renderNodes(falseNodes, context)
Template.swift:42
    return try renderNodes(nodes, context ?? Context())
(nodes:[NodeType], _ context:Context) throws -> String { 0022 return try nodes.map { try $0.render(context) }.joinWithSeparator("") 0023 } 0024 0025 public class SimpleNode
Namespace.swift:38
      return SimpleNode(handler: handler)
: NodeType { 0026 let handler
Node.swift:29
    self.handler = handler
Node.swift:33
    return try handler(context)
:Context throws -> String 0027 0028 public init
Namespace.swift:38
      return SimpleNode(handler: handler)
(handler:Context throws -> String) { 0029 self.handler = handler 0030 } 0031 0032 public func render(context: Context) throws -> String { 0033 return try handler(context) 0034 } 0035 } 0036 0037 public class TextNode
Parser.swift:42
        nodes.append(TextNode(text: text))
: NodeType { 0038 public let text
Node.swift:41
    self.text = text
Node.swift:45
    return self.text
:String 0039 0040 public init
Parser.swift:42
        nodes.append(TextNode(text: text))
(text:String) { 0041 self.text = text 0042 } 0043 0044 public func render(context:Context) throws -> String { 0045 return self.text 0046 } 0047 } 0048 0049 public protocol Resolvable
Node.swift:54
  public let variable: Resolvable
Node.swift:56
  public init(variable: Resolvable) {
Parser.swift:88
  func compileFilter(token: String) throws -> Resolvable {
Variable.swift:4
class FilterExpression : Resolvable {
Variable.swift:37
public struct Variable : Equatable, Resolvable {
{ 0050 func resolve
Node.swift:65
    let result = try variable.resolve(context)
(context: Context) throws -> Any? 0051 } 0052 0053 public class VariableNode
Parser.swift:44
        nodes.append(VariableNode(variable: try compileFilter(token.contents)))
: NodeType { 0054 public let variable
Node.swift:57
    self.variable = variable
Node.swift:61
    self.variable = Variable(variable)
Node.swift:65
    let result = try variable.resolve(context)
: Resolvable 0055 0056 public init
Parser.swift:44
        nodes.append(VariableNode(variable: try compileFilter(token.contents)))
(variable: Resolvable) { 0057 self.variable = variable 0058 } 0059 0060 public init(variable: String) { 0061 self.variable = Variable(variable) 0062 } 0063 0064 public func render(context: Context) throws -> String { 0065 let result = try variable.resolve(context) 0066 0067 if let result = result as? String { 0068 return result 0069 } else if let result = result as? CustomStringConvertible { 0070 return result.description 0071 } else if let result = result as? NSObject { 0072 return result.description 0073 } 0074 0075 return "" 0076 } 0077 } 0078 0079 0080 #if !os(Linux) 0081 public class NowNode
Namespace.swift:17
    registerTag("now", parser: NowNode.parse)
Node.swift:95
    return NowNode(format:format)
: NodeType { 0082 public let format
Node.swift:99
    self.format = format ?? Variable("\"yyyy-MM-dd 'at' HH:mm\"")
Node.swift:104
    let format = try self.format.resolve(context)
:Variable 0083 0084 public class func parse
Namespace.swift:17
    registerTag("now", parser: NowNode.parse)
(parser:TokenParser, token:Token) throws -> NodeType { 0085 var format:Variable? 0086 0087 let components = token.components() 0088 guard components.count <= 2 else { 0089 throw TemplateSyntaxError("'now' tags may only have one argument: the format string `\(token.contents)`.") 0090 } 0091 if components.count == 2 { 0092 format = Variable(components[1]) 0093 } 0094 0095 return NowNode(format:format) 0096 } 0097 0098 public init
Node.swift:95
    return NowNode(format:format)
(format:Variable?) { 0099 self.format = format ?? Variable("\"yyyy-MM-dd 'at' HH:mm\"") 0100 } 0101 0102 public func render(context: Context) throws -> String { 0103 let date = NSDate() 0104 let format = try self.format.resolve(context) 0105 var formatter:NSDateFormatter? 0106 0107 if let format = format as? NSDateFormatter { 0108 formatter = format 0109 } else if let format = format as? String { 0110 formatter = NSDateFormatter() 0111 formatter!.dateFormat = format 0112 } else { 0113 return "" 0114 } 0115 0116 return formatter!.stringFromDate(date) 0117 } 0118 } 0119 #endif 0120 0121 0122 public class ForNode
Namespace.swift:13
    registerTag("for", parser: ForNode.parse)
Node.swift:151
    return ForNode(variable: variable, loopVariable: loopVariable, nodes: forNodes, emptyNodes:emptyNodes)
: NodeType { 0123 let variable
Node.swift:155
    self.variable = Variable(variable)
Node.swift:162
    let values = try variable.resolve(context)
:Variable 0124 let loopVariable
Node.swift:156
    self.loopVariable = loopVariable
Node.swift:173
        return try context.push([loopVariable: item, "forloop": forContext]) {
:String 0125 let nodes
Node.swift:157
    self.nodes = nodes
Node.swift:174
          try renderNodes(nodes, context)
:[NodeType] 0126 let emptyNodes
Node.swift:158
    self.emptyNodes = emptyNodes
Node.swift:180
      try renderNodes(emptyNodes, context)
: [NodeType] 0127 0128 public class func parse
Namespace.swift:13
    registerTag("for", parser: ForNode.parse)
(parser:TokenParser, token:Token) throws -> NodeType { 0129 let components = token.components() 0130 0131 guard components.count == 4 && components[2] == "in" else { 0132 throw TemplateSyntaxError("'for' statements should use the following 'for x in y' `\(token.contents)`.") 0133 } 0134 0135 let loopVariable = components[1] 0136 let variable = components[3] 0137 0138 var emptyNodes = [NodeType]() 0139 0140 let forNodes = try parser.parse(until(["endfor", "empty"])) 0141 0142 guard let token = parser.nextToken() else { 0143 throw TemplateSyntaxError("`endfor` was not found.") 0144 } 0145 0146 if token.contents == "empty" { 0147 emptyNodes = try parser.parse(until(["endfor"])) 0148 parser.nextToken() 0149 } 0150 0151 return ForNode(variable: variable, loopVariable: loopVariable, nodes: forNodes, emptyNodes:emptyNodes) 0152 } 0153 0154 public init
Node.swift:151
    return ForNode(variable: variable, loopVariable: loopVariable, nodes: forNodes, emptyNodes:emptyNodes)
(variable:String, loopVariable:String, nodes:[NodeType], emptyNodes:[NodeType]) { 0155 self.variable = Variable(variable) 0156 self.loopVariable = loopVariable 0157 self.nodes = nodes 0158 self.emptyNodes = emptyNodes 0159 } 0160 0161 public func render(context: Context) throws -> String { 0162 let values = try variable.resolve(context) 0163 0164 if let values = values as? [Any] where values.count > 0 { 0165 let count = values.count 0166 return try values.enumerate().map { index, item in 0167 let forContext: [String: Any] = [ 0168 "first": index == 0, 0169 "last": index == (count - 1), 0170 "counter": index + 1, 0171 ] 0172 0173 return try context.push([loopVariable: item, "forloop": forContext]) { 0174 try renderNodes(nodes, context) 0175 } 0176 }.joinWithSeparator("") 0177 } 0178 0179 return try context.push { 0180 try renderNodes(emptyNodes, context) 0181 } 0182 } 0183 } 0184 0185 public class IfNode
Namespace.swift:14
    registerTag("if", parser: IfNode.parse)
Namespace.swift:15
    registerTag("ifnot", parser: IfNode.parse_ifnot)
Node.swift:210
    return IfNode(variable: variable, trueNodes: trueNodes, falseNodes: falseNodes)
Node.swift:233
    return IfNode(variable: variable, trueNodes: trueNodes, falseNodes: falseNodes)
: NodeType { 0186 public let variable
Node.swift:237
    self.variable = Variable(variable)
Node.swift:243
    let result = try variable.resolve(context)
:Variable 0187 public let trueNodes
Node.swift:238
    self.trueNodes = trueNodes
Node.swift:257
      output = try renderNodes(trueNodes, context)
:[NodeType] 0188 public let falseNodes
Node.swift:239
    self.falseNodes = falseNodes
Node.swift:259
      output = try renderNodes(falseNodes, context)
:[NodeType] 0189 0190 public class func parse
Namespace.swift:14
    registerTag("if", parser: IfNode.parse)
(parser:TokenParser, token:Token) throws -> NodeType { 0191 let components = token.components() 0192 guard components.count == 2 else { 0193 throw TemplateSyntaxError("'if' statements should use the following 'if condition' `\(token.contents)`.") 0194 } 0195 let variable = components[1] 0196 var trueNodes = [NodeType]() 0197 var falseNodes = [NodeType]() 0198 0199 trueNodes = try parser.parse(until(["endif", "else"])) 0200 0201 guard let token = parser.nextToken() else { 0202 throw TemplateSyntaxError("`endif` was not found.") 0203 } 0204 0205 if token.contents == "else" { 0206 falseNodes = try parser.parse(until(["endif"])) 0207 parser.nextToken() 0208 } 0209 0210 return IfNode(variable: variable, trueNodes: trueNodes, falseNodes: falseNodes) 0211 } 0212 0213 public class func parse_ifnot
Namespace.swift:15
    registerTag("ifnot", parser: IfNode.parse_ifnot)
(parser:TokenParser, token:Token) throws -> NodeType { 0214 let components = token.components() 0215 guard components.count == 2 else { 0216 throw TemplateSyntaxError("'ifnot' statements should use the following 'if condition' `\(token.contents)`.") 0217 } 0218 let variable = components[1] 0219 var trueNodes = [NodeType]() 0220 var falseNodes = [NodeType]() 0221 0222 falseNodes = try parser.parse(until(["endif", "else"])) 0223 0224 guard let token = parser.nextToken() else { 0225 throw TemplateSyntaxError("`endif` was not found.") 0226 } 0227 0228 if token.contents == "else" { 0229 trueNodes = try parser.parse(until(["endif"])) 0230 parser.nextToken() 0231 } 0232 0233 return IfNode(variable: variable, trueNodes: trueNodes, falseNodes: falseNodes) 0234 } 0235 0236 public init
Node.swift:210
    return IfNode(variable: variable, trueNodes: trueNodes, falseNodes: falseNodes)
Node.swift:233
    return IfNode(variable: variable, trueNodes: trueNodes, falseNodes: falseNodes)
(variable:String, trueNodes:[NodeType], falseNodes:[NodeType]) { 0237 self.variable = Variable(variable) 0238 self.trueNodes = trueNodes 0239 self.falseNodes = falseNodes 0240 } 0241 0242 public func render(context: Context) throws -> String { 0243 let result = try variable.resolve(context) 0244 var truthy = false 0245 0246 if let result = result as? [Any] { 0247 truthy = !result.isEmpty 0248 } else if let result = result as? [String:Any] { 0249 truthy = !result.isEmpty 0250 } else if result != nil { 0251 truthy = true 0252 } 0253 0254 context.push() 0255 let output:String 0256 if truthy { 0257 output = try renderNodes(trueNodes, context) 0258 } else { 0259 output = try renderNodes(falseNodes, context) 0260 } 0261 context.pop() 0262 0263 return output 0264 } 0265 } 0266