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
.JSGeneration
17 using DynamicDispatching
;
23 public abstract class AbstractJSGenerator
: IJSGenerator
25 private readonly IJSCodeGenerator codeGenerator
;
28 /// Initializes a new instance of the <see cref="AbstractJSGenerator"/> class.
30 /// <param name="codeGenerator">The code generator.</param>
31 protected AbstractJSGenerator(IJSCodeGenerator codeGenerator
)
33 this.codeGenerator
= codeGenerator
;
40 public abstract void InsertHtml(string position
, string id
, object renderOptions
);
46 public abstract void ReplaceHtml(string id
, object renderOptions
);
52 public abstract void Replace(string id
, object renderOptions
);
58 public abstract void Show(params string[] ids
);
64 public abstract void Hide(params string[] ids
);
70 public abstract void Toggle(params string[] ids
);
76 public abstract void Remove(params string[] ids
);
79 /// Outputs the content using the renderOptions approach.
81 /// If the renderOptions is a string, the content is escaped and quoted.
84 /// If the renderOptions is a dictionary, we extract the key <c>partial</c>
85 /// and evaluate the template it points to. The content is escaped and quoted.
88 /// <param name="renderOptions">The render options.</param>
89 /// <returns></returns>
91 /// The following example uses nvelocity syntax:
93 /// $page.Call('myJsFunction', $page.render("%{partial='shared/newmessage.vm'}") )
99 /// myJsFunction('the content from the newmessage partial view template')
103 public virtual object Render(object renderOptions
)
105 return CodeGenerator
.Render(renderOptions
);
109 /// Creates a generator for an element.
111 /// <param name="root">The root expression.</param>
112 /// <returns></returns>
113 public abstract IJSElementGenerator
CreateElementGenerator(string root
);
116 /// Gets the code generator instance.
118 /// <value>The code generator.</value>
119 public IJSCodeGenerator CodeGenerator
121 get { return codeGenerator; }
125 /// Quotes the specified content.
127 /// <param name="content">The content.</param>
128 /// <returns></returns>
129 protected string Quote(string content
)
131 return AbstractHelper
.Quote(content
);
135 /// Quotes the specified content array.
137 /// <param name="content">The content array.</param>
138 /// <returns></returns>
139 protected string[] Quote(object[] content
)
141 return AbstractHelper
.Quote(content
);