1
// Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.MonoRail
.Framework
.Test
18 using System
.Collections
.Generic
;
20 using Castle
.MonoRail
.Framework
.JSGeneration
.Prototype
;
26 public class ViewEngineManagerStub
: IViewEngineManager
28 private readonly List
<string> templates
= new List
<string>();
29 private string templateRendered
;
30 private string partialRendered
;
31 private string contentWithinLayoutRendered
;
34 /// Gets the name of the template rendered by the controller.
36 /// <value>The template rendered.</value>
37 public string TemplateRendered
39 get { return templateRendered; }
43 /// Gets the name of the partial template rendered.
45 /// <value>The partial rendered.</value>
46 public string PartialRendered
48 get { return partialRendered; }
52 /// Gets the static content rendered from the controller.
54 /// <value>The content within layout rendered.</value>
55 public string ContentWithinLayoutRendered
57 get { return contentWithinLayoutRendered; }
61 /// Registers the template.
63 /// <param name="template">The template.</param>
64 public void RegisterTemplate(string template
)
66 templates
.Add(template
);
70 /// Evaluates whether the specified template exists.
72 /// <param name="templateName"></param>
73 /// <returns><c>true</c> if it exists</returns>
74 public bool HasTemplate(string templateName
)
76 return templates
.Exists(
77 delegate(string item
) { return item.Equals(templateName, StringComparison.InvariantCultureIgnoreCase); }
);
81 /// Processes the view - using the templateName
82 /// to obtain the correct template
83 /// and writes the results to the System.TextWriter.
85 /// Please note that no layout is applied
88 public void Process(string templateName
, TextWriter output
, IEngineContext context
, IController controller
,
89 IControllerContext controllerContext
)
91 templateRendered
= templateName
;
95 /// Processes the view - using the templateName
96 /// to obtain the correct template
97 /// and writes the results to the System.TextWriter.
99 public void Process(string templateName
, string layoutName
, TextWriter output
, IDictionary
<string, object> parameters
)
101 templateRendered
= templateName
;
105 /// Processes a partial view using the partialName
106 /// to obtain the correct template and writes the
107 /// results to the System.TextWriter.
109 public void ProcessPartial(string partialName
, TextWriter output
, IEngineContext context
, IController controller
,
110 IControllerContext controllerContext
)
112 partialRendered
= partialName
;
116 /// Wraps the specified content in the layout using
117 /// the context to output the result.
119 public void RenderStaticWithinLayout(string contents
, IEngineContext context
, IController controller
,
120 IControllerContext controllerContext
)
122 contentWithinLayoutRendered
= contents
;
126 /// Creates the JS code generator info. Temporarily on IViewEngineManager
128 /// <param name="engineContext">The engine context.</param>
129 /// <param name="controller">The controller.</param>
130 /// <param name="controllerContext">The controller context.</param>
131 /// <returns></returns>
132 public JSCodeGeneratorInfo
CreateJSCodeGeneratorInfo(IEngineContext engineContext
, IController controller
,
133 IControllerContext controllerContext
)
135 JSCodeGenerator codeGen
= new JSCodeGenerator();
137 return new JSCodeGeneratorInfo(codeGen
, new PrototypeGenerator(codeGen
), new object[0], new object[0]);