private string Render(params object[] args) { try { // Converts the incoming object arguments to proper TemplateArguments TemplateArguments arguments = new TemplateArguments(args); string pageTemplate = _templateMgr.Render("views\\user\\" + MethodName + ".haml", arguments); arguments.Clear(); arguments.Add("text", pageTemplate); return(_templateMgr.Render("views\\layouts\\application.haml", arguments)); } catch (FileNotFoundException err) { throw new NotFoundException("Failed to find template. Details: " + err.Message, err); } catch (InvalidOperationException err) { throw new InternalServerException("Failed to render template. Details: " + err.Message, err); } catch (TemplateException err) { throw new InternalServerException("Failed to compile template. Details: " + err.Message, err); } catch (ArgumentException err) { throw new InternalServerException("Failed to render templates", err); } }
/// <summary> /// Render a template. /// </summary> /// <remarks>Merges the Arguments property with the <c>args</c> parameter and pass those to the template.</remarks> /// <param name="controller">controller name are used as a folder name when looking for the template.</param> /// <param name="method">method are used as filename when looking for the template.</param> /// <param name="args">arguments that should be passed to the template.</param> /// <returns></returns> protected string RenderTemplate(string controller, string method, params object[] args) { try { TemplateArguments args2 = MergeArguments(args); _arguments.Clear(); string result = _templateMgr.Render(controller + "\\" + method + ".*", args2); _errors.Clear(); return(result); } catch (FileNotFoundException err) { throw new NotFoundException("Failed to find template. Details: " + err.Message, err); } catch (InvalidOperationException err) { throw new InternalServerException("Failed to render template. Details: " + err.Message, err); } catch (Fadd.CompilerException err) { throw new TemplateException("Could not compile template '" + controller + "/" + method + "/'", err); } catch (CodeGeneratorException err) { #if DEBUG string error = "Line: " + err.LineNumber + "<br />\r\n" + err.ToString().Replace("\r\n", "<br />\r\n"); throw new InternalServerException(error, err); #else throw new InternalServerException("Failed to compile template.", err); #endif } catch (ArgumentException err) { #if DEBUG throw new InternalServerException( "Failed to render template, reason: " + err.ToString().Replace("\r\n", "<br />\r\n"), err); #else throw new InternalServerException("Failed to render templates", err); #endif } }