Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 public void TestDuplicate()
 {
     _arguments = new TemplateArguments("Test", 1);
     Assert.Throws(typeof (ArgumentException), delegate
                                                   {
                                                       _arguments.Add("Test", 2);
                                                   });
 }
Exemplo n.º 3
0
 public void TestNullObject()
 {
     _arguments = new TemplateArguments();
     Assert.Throws(typeof(ArgumentNullException), delegate { _arguments.Add("Test", null); });
 }
Exemplo n.º 4
0
        public void TestWrongTypeSubmitted()
        {

            _arguments = new TemplateArguments();
            Assert.Throws(typeof (ArgumentException), delegate { _arguments.Add("TestString", 4, typeof (float)); });
        }
Exemplo n.º 5
0
        /// <summary>
        /// Merge arguments array and Arguments property.
        /// </summary>
        /// <param name="args">Arguments array to merge</param>
        /// <returns>arguments/parameters that can be used in the template.</returns>
        /// <remarks>Will add Request/Response/Session arguments</remarks>
        private TemplateArguments MergeArguments(object[] args)
        {
            // Create a new argument holder
            TemplateArguments arguments = new TemplateArguments();
            arguments.Add("Request", Request, typeof(IHttpRequest));
            arguments.Add("Response", Response);
            arguments.Add("Session", Session);
            arguments.Add("Controller", this, typeof(ViewController));
			arguments.Update(_arguments);
			arguments.Update(new TemplateArguments(args));

            return arguments;
        }