Added non-generic registration interface to IKernel and IWindsor to accommodate dynam...
[castle.git] / MonoRail / Castle.MonoRail.Framework / ViewComponents / ChildContentComponent.cs
blob938943dab1aae233184aaafcd8c9c69a74543908
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.ViewComponents
17 using System;
18 using System.Collections;
19 using System.IO;
21 /// <summary>
22 /// Renders the contents of the block component into the $childContent context
23 /// variable, and then renders the components view file.
24 /// </summary>
25 /// <example>
26 /// Controller view:
27 /// <code>
28 /// #blockcomponent(ChildContentComponent)
29 /// This will be rendered inside a div tag.
30 /// #end
31 /// </code>
32 ///
33 /// ViewComponent view:
34 /// <code>
35 /// &lt;div&gt;$componentChildContent&lt;/&gt;
36 /// </code>
37 /// </example>
38 public class ChildContentComponent : ViewComponent
40 private readonly String EntryKey = "componentChildContent";
42 /// <summary>
43 /// Obtains the content of the child.
44 /// </summary>
45 protected virtual void ObtainChildContent()
47 StringWriter writer = new StringWriter();
49 Context.RenderBody(writer);
51 Context.ContextVars[EntryKey] = writer.ToString();
54 /// <summary>
55 /// Populates the context.
56 /// </summary>
57 protected void PopulateContext()
59 foreach(DictionaryEntry value in ComponentParams)
61 Context.ContextVars[value.Key] = value.Value;
65 /// <summary>
66 /// Called by the framework so the component can
67 /// render its content
68 /// </summary>
69 public override void Render()
71 RenderView("default");
74 /// <summary>
75 /// Specifies the view to be processed after the component has finished its processing.
76 /// </summary>
77 /// <param name="name"></param>
78 protected new void RenderView(string name)
80 PopulateContext();
81 ObtainChildContent();
83 base.RenderView(name);
86 /// <summary>
87 /// Specifies the view to be processed after the component has finished its processing.
88 /// </summary>
89 /// <param name="component"></param>
90 /// <param name="name"></param>
91 protected new void RenderView(string component, string name)
93 PopulateContext();
94 ObtainChildContent();
96 base.RenderView(component, name);