guard all the things! 👮
This commit is contained in:
@@ -8,7 +8,7 @@ public class IncludeNode : NodeType {
|
||||
public class func parse(parser:TokenParser, token:Token) throws -> NodeType {
|
||||
let bits = token.contents.componentsSeparatedByString("\"")
|
||||
|
||||
if bits.count != 3 {
|
||||
guard bits.count == 3 else {
|
||||
throw TemplateSyntaxError("'include' tag takes one argument, the template file to be included")
|
||||
}
|
||||
|
||||
@@ -20,18 +20,16 @@ public class IncludeNode : NodeType {
|
||||
}
|
||||
|
||||
public func render(context: Context) throws -> String {
|
||||
if let loader = context["loader"] as? TemplateLoader {
|
||||
if let template = loader.loadTemplate(templateName) {
|
||||
return try template.render(context)
|
||||
}
|
||||
|
||||
let paths:String = loader.paths.map { path in
|
||||
return path.description
|
||||
}.joinWithSeparator(", ")
|
||||
throw TemplateSyntaxError("'\(templateName)' template not found in \(paths)")
|
||||
guard let loader = context["loader"] as? TemplateLoader else {
|
||||
throw TemplateSyntaxError("Template loader not in context")
|
||||
}
|
||||
|
||||
throw TemplateSyntaxError("Template loader not in context")
|
||||
guard let template = loader.loadTemplate(templateName) else {
|
||||
let paths:String = loader.paths.map { $0.description }.joinWithSeparator(", ")
|
||||
throw TemplateSyntaxError("'\(templateName)' template not found in \(paths)")
|
||||
}
|
||||
|
||||
return try template.render(context)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user