guard all the things! 👮

This commit is contained in:
Olivier Halligon
2015-10-18 06:57:41 +02:00
parent f0abd34c32
commit f4ed872a45
4 changed files with 58 additions and 62 deletions

View File

@@ -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)
}
}