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
.Views
.IronView
21 class DefaultContext
: ITemplateContext
23 private readonly string rootViewName
;
24 private readonly XmlReader reader
;
25 private readonly IServiceProvider serviceProvider
;
26 private readonly ITemplateEngine engine
;
27 private int currentElementDepth
;
28 private int indentation
;
29 private StringBuilder script
= new StringBuilder();
32 /// Initializes a new instance of the <see cref="DefaultContext"/> class.
34 /// <param name="rootViewName">Name of the root view.</param>
35 /// <param name="reader">The reader.</param>
36 /// <param name="serviceProvider">The service provider.</param>
37 public DefaultContext(String rootViewName
, XmlReader reader
,
38 IServiceProvider serviceProvider
, ITemplateEngine engine
)
40 this.rootViewName
= rootViewName
;
42 this.serviceProvider
= serviceProvider
;
46 public XmlReader Reader
48 get { return reader; }
51 public IServiceProvider ServiceProvider
53 get { return serviceProvider; }
56 public ITemplateEngine Engine
58 get { return engine; }
61 public string RootViewName
63 get { return rootViewName; }
66 public StringBuilder Script
68 get { return script; }
71 public int Indentation
73 get { return indentation; }
76 public int CurrentElementDepth
78 get { return currentElementDepth; }
81 public void IncreaseIndentation()
86 public void DecreaseIndentation()
91 public void IncreaseDepth()
93 currentElementDepth
++;
96 public void DecreaseDepth()
98 currentElementDepth
--;
101 public void AppendIndented(string content
)
105 script
.Append(content
);
108 public void AppendLineIndented(string content
)
112 script
.AppendLine(content
);
115 private void Indent()
117 for(int i
= 0; i
< indentation
; i
++)