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
17 using System
.Collections
.Generic
;
19 using Castle
.MonoRail
.Framework
.JSGeneration
.Prototype
;
24 public class ViewEngineStub
: ViewEngineBase
26 private string viewFileExtension
;
27 private bool supportsJSGeneration
;
28 private string jsGeneratorFileExtension
;
29 private readonly List
<string> jsTemplateRendered
= new List
<string>();
30 private readonly List
<string> templateRendered
= new List
<string>();
31 private readonly List
<string> partialRendered
= new List
<string>();
34 /// Initializes a new instance of the <see cref="ViewEngineStub"/> class.
36 /// <param name="viewFileExtension">The view file extension.</param>
37 /// <param name="supportsJSGeneration">if set to <c>true</c> [supports JS generation].</param>
38 /// <param name="jsGeneratorFileExtension">The js generator file extension.</param>
39 public ViewEngineStub(string viewFileExtension
, string jsGeneratorFileExtension
, bool supportsJSGeneration
)
41 this.viewFileExtension
= viewFileExtension
;
42 this.supportsJSGeneration
= supportsJSGeneration
;
43 this.jsGeneratorFileExtension
= jsGeneratorFileExtension
;
47 /// Initializes a new instance of the <see cref="ViewEngineStub"/> class.
49 public ViewEngineStub() : this(".mm", ".jsm", true)
54 /// Gets a list of partial templates that were "rendered" since the stub was created.
56 /// <value>The partial rendered.</value>
57 public List
<string> PartialRendered
59 get { return partialRendered; }
63 /// Gets a list of templates that were "rendered" since the stub was created.
65 /// <value>The template rendered.</value>
66 public List
<string> TemplateRendered
68 get { return templateRendered; }
72 /// Gets a list of js templates that were "rendered" since the stub was created.
74 /// <value>The js template rendered.</value>
75 public List
<string> JsTemplateRendered
77 get { return jsTemplateRendered; }
81 /// Gets the view file extension.
83 /// <value>The view file extension.</value>
84 public override string ViewFileExtension
86 get { return viewFileExtension; }
90 /// Gets a value indicating whether the view engine
91 /// support the generation of JS.
94 /// <c>true</c> if JS generation is supported; otherwise, <c>false</c>.
96 public override bool SupportsJSGeneration
98 get { return supportsJSGeneration; }
102 /// Gets the JS generator file extension.
104 /// <value>The JS generator file extension.</value>
105 public override string JSGeneratorFileExtension
107 get { return jsGeneratorFileExtension; }
111 /// Returns a prototype generator.
113 /// <param name="generatorInfo"></param>
114 /// <param name="context"></param>
115 /// <param name="controller"></param>
116 /// <param name="controllerContext"></param>
117 /// <returns></returns>
118 public override object CreateJSGenerator(JSCodeGeneratorInfo generatorInfo
, IEngineContext context
,
119 IController controller
, IControllerContext controllerContext
)
121 return new PrototypeGenerator(generatorInfo
.CodeGenerator
);
125 /// Records on <see cref="JsTemplateRendered"/> the js template
128 /// <param name="templateName">Name of the template.</param>
129 /// <param name="output">The output.</param>
130 /// <param name="generatorInfo">The generator info.</param>
131 /// <param name="context">The request context.</param>
132 /// <param name="controller">The controller.</param>
133 /// <param name="controllerContext">The controller context.</param>
134 public override void GenerateJS(string templateName
, TextWriter output
, JSCodeGeneratorInfo generatorInfo
,
135 IEngineContext context
, IController controller
, IControllerContext controllerContext
)
137 jsTemplateRendered
.Add(templateName
);
141 /// Records on <see cref="TemplateRendered"/> the template
144 /// <param name="templateName"></param>
145 /// <param name="output"></param>
146 /// <param name="context"></param>
147 /// <param name="controller"></param>
148 /// <param name="controllerContext"></param>
149 public override void Process(string templateName
, TextWriter output
, IEngineContext context
, IController controller
,
150 IControllerContext controllerContext
)
152 templateRendered
.Add(templateName
);
156 /// Records on <see cref="TemplateRendered"/> the template
159 /// <param name="templateName"></param>
160 /// <param name="layoutName"></param>
161 /// <param name="output"></param>
162 /// <param name="parameters"></param>
163 public override void Process(string templateName
, string layoutName
, TextWriter output
,
164 IDictionary
<string, object> parameters
)
166 templateRendered
.Add(templateName
);
170 /// Records on <see cref="PartialRendered"/> the partial template
173 /// <param name="partialName">The partial name.</param>
174 /// <param name="output">The output.</param>
175 /// <param name="context">The request context.</param>
176 /// <param name="controller">The controller.</param>
177 /// <param name="controllerContext">The controller context.</param>
178 public override void ProcessPartial(string partialName
, TextWriter output
, IEngineContext context
,
179 IController controller
, IControllerContext controllerContext
)
181 partialRendered
.Add(partialName
);
185 /// Records on <see cref="PartialRendered"/> the partial template
188 /// <param name="contents"></param>
189 /// <param name="context"></param>
190 /// <param name="controller"></param>
191 /// <param name="controllerContext"></param>
192 public override void RenderStaticWithinLayout(string contents
, IEngineContext context
, IController controller
,
193 IControllerContext controllerContext
)
195 partialRendered
.Add(contents
);