1 // Copyright 2004-2007 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 using Directive
= NVelocity
.Runtime
.Directive
.Directive
;
16 using DirectiveType
= NVelocity
.Runtime
.Directive
.DirectiveType
;
17 using IInternalContextAdapter
= NVelocity
.Context
.IInternalContextAdapter
;
18 using INode
= NVelocity
.Runtime
.Parser
.Node
.INode
;
19 using IRuntimeServices
= NVelocity
.Runtime
.IRuntimeServices
;
21 namespace Castle
.MonoRail
.Framework
.Views
.NVelocity
.CustomDirectives
24 using System
.Collections
;
27 public class SubSectionDirective
: Directive
29 private readonly string name
;
30 private NVelocityViewContextAdapter contextAdapter
;
31 private INode savedNode
;
33 public SubSectionDirective(String name
)
39 /// Return the name of this directive
41 public override String Name
44 set { throw new NotImplementedException(); }
48 /// Get the directive type BLOCK/LINE
50 public override DirectiveType Type
52 get { return DirectiveType.BLOCK; }
55 public override bool AcceptParams
61 /// How this directive is to be initialized.
63 public override void Init(IRuntimeServices rs
, IInternalContextAdapter context
, INode node
)
65 base.Init(rs
, context
, node
);
71 /// How this directive is to be rendered
73 public override bool Render(IInternalContextAdapter context
, TextWriter writer
, INode node
)
77 throw new RailsException("context is null");
80 if (contextAdapter
== null)
82 throw new RailsException("contextAdapter is null");
85 if (contextAdapter
.ContextVars
== null)
87 throw new RailsException("contextAdapter.ContextVars is null");
90 foreach(DictionaryEntry entry
in contextAdapter
.ContextVars
)
92 context
.Put(entry
.Key
.ToString(), entry
.Value
);
95 for(int i
=0; i
< savedNode
.ChildrenCount
; i
++)
97 INode childNode
= savedNode
.GetChild(i
);
98 childNode
.Render(context
, writer
);
104 internal NVelocityViewContextAdapter ContextAdapter
106 set { contextAdapter = value; }