Resolve extends and include arguments as variables
This commit is contained in:
@@ -2,19 +2,19 @@ import PathKit
|
||||
|
||||
|
||||
public class IncludeNode : NodeType {
|
||||
public let templateName: String
|
||||
public let templateName: Variable
|
||||
|
||||
public class func parse(parser: TokenParser, token: Token) throws -> NodeType {
|
||||
let bits = token.contents.characters.split("\"", allowEmptySlices: true).map(String.init)
|
||||
let bits = token.components()
|
||||
|
||||
guard bits.count == 3 else {
|
||||
guard bits.count == 2 else {
|
||||
throw TemplateSyntaxError("'include' tag takes one argument, the template file to be included")
|
||||
}
|
||||
|
||||
return IncludeNode(templateName: bits[1])
|
||||
return IncludeNode(templateName: Variable(bits[1]))
|
||||
}
|
||||
|
||||
public init(templateName: String) {
|
||||
public init(templateName: Variable) {
|
||||
self.templateName = templateName
|
||||
}
|
||||
|
||||
@@ -23,6 +23,10 @@ public class IncludeNode : NodeType {
|
||||
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)")
|
||||
|
||||
Reference in New Issue
Block a user