Add Package.swift and move files around

This commit is contained in:
Boris Bügling
2015-12-08 11:45:03 +01:00
parent 0bfd4134f9
commit 372b2e7576
35 changed files with 22 additions and 11 deletions

38
Sources/Include.swift Normal file
View File

@@ -0,0 +1,38 @@
import PathKit
public class IncludeNode : NodeType {
public let templateName: Variable
public class func parse(parser: TokenParser, token: Token) throws -> NodeType {
let bits = token.components()
guard bits.count == 2 else {
throw TemplateSyntaxError("'include' tag takes one argument, the template file to be included")
}
return IncludeNode(templateName: Variable(bits[1]))
}
public init(templateName: Variable) {
self.templateName = templateName
}
public func render(context: Context) throws -> String {
guard let loader = context["loader"] as? TemplateLoader else {
throw TemplateSyntaxError("Template loader not in context")
}
guard let templateName = try self.templateName.resolve(context) as? String else {
throw TemplateSyntaxError("'\(self.templateName)' could not be resolved as a string")
}
guard let template = loader.loadTemplate(templateName) else {
let paths = loader.paths.map { $0.description }.joinWithSeparator(", ")
throw TemplateSyntaxError("'\(templateName)' template not found in \(paths)")
}
return try template.render(context)
}
}