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
18 using System
.Collections
;
19 using Castle
.MonoRail
.Framework
;
20 using Castle
.MonoRail
.Framework
.Helpers
;
21 using Castle
.MonoRail
.Framework
.Services
;
24 /// Depicts the contract for javascript generators.
29 /// Urls can be specified as string or a dictionary. If the latter, the <see cref="UrlHelper"/>
30 /// is used. See <see cref="DefaultUrlBuilder.BuildUrl(UrlInfo,IDictionary)"/>
34 /// The <c>renderOptions</c> is also a common parameter. If you pass a string,
35 /// the string will be rendered. If it is a dictionary, it instructs the infrastructure to
36 /// render a partial content. The dictionary must contain an entry named <c>partial</c>
37 /// with the absolute path to the view to render.
43 /// The following is an example of using it with a nvelocity
44 /// syntax and renders static content:
47 /// $page.InsertHtml('Bottom', 'messagestable', "Message sent")
51 /// The following uses a partial view:
55 /// $page.InsertHtml('Bottom', 'messagestable', "%{partial='shared/newmessage.vm'}")
59 /// The following redirects to a static page
63 /// $page.RedirectTo('about.aspx')
67 /// The following redirects using the <see cref="UrlHelper"/>
71 /// $page.RedirectTo("%{controller='Home',action='index'}")
75 public interface IJSGenerator
78 /// Inserts a content snippet relative to the element specified by the <paramref name="id"/>
81 /// The supported positions are
82 /// Top, After, Before, Bottom
87 /// The following example uses nvelocity syntax:
90 /// $page.InsertHtml('Bottom', 'messagestable', "%{partial='shared/newmessage.vm'}")
94 /// <param name="position">The position to insert the content relative to the element id</param>
95 /// <param name="id">The target element id</param>
96 /// <param name="renderOptions">Defines what to render</param>
97 void InsertHtml(string position
, string id
, object renderOptions
);
100 /// Replaces the content of the specified target element.
104 /// The following example uses nvelocity syntax:
107 /// $page.ReplaceHtml('messagediv', "%{partial='shared/newmessage.vm'}")
111 /// <param name="id">The target element id</param>
112 /// <param name="renderOptions">Defines what to render</param>
113 void ReplaceHtml(String id
, object renderOptions
);
116 /// Replaces the entire target element -- and not only its innerHTML --
117 /// by the content evaluated.
121 /// The following example uses nvelocity syntax:
124 /// $page.Replace('messagediv', "%{partial='shared/newmessage.vm'}")
128 /// <param name="id">The target element id</param>
129 /// <param name="renderOptions">Defines what to render</param>
130 void Replace(String id
, object renderOptions
);
133 /// Shows the specified elements.
137 /// The elements must exist.
141 /// The following example uses nvelocity syntax:
144 /// $page.Show('div1', 'div2')
148 /// <param name="ids">The elements ids.</param>
149 void Show(params string[] ids
);
152 /// Hides the specified elements.
156 /// The elements must exist.
160 /// The following example uses nvelocity syntax:
163 /// $page.Hide('div1', 'div2')
167 /// <param name="ids">The elements ids.</param>
168 void Hide(params string[] ids
);
171 /// Toggles the display status of the specified elements.
175 /// The elements must exist.
179 /// The following example uses nvelocity syntax:
182 /// $page.Toggle('div1', 'div2')
186 /// <param name="ids">The elements ids.</param>
187 void Toggle(params string[] ids
);
190 /// Remove the specified elements from the DOM.
194 /// The elements must exist.
198 /// The following example uses nvelocity syntax:
201 /// $page.Remove('div1', 'div2')
205 /// <param name="ids">The elements ids.</param>
206 void Remove(params string[] ids
);
209 /// Outputs the content using the renderOptions approach.
212 /// If the renderOptions is a string, the content is escaped and quoted.
216 /// If the renderOptions is a dictionary, we extract the key <c>partial</c>
217 /// and evaluate the template it points to. The content is escaped and quoted.
223 /// The following example uses nvelocity syntax:
226 /// $page.Call('myJsFunction', $page.render("%{partial='shared/newmessage.vm'}") )
234 /// myJsFunction('the content from the newmessage partial view template')
239 /// <param name="renderOptions">The render options.</param>
240 /// <returns></returns>
241 object Render(object renderOptions
);
244 /// Creates a generator for an element.
246 /// <param name="root">The root expression.</param>
247 /// <returns></returns>
248 IJSElementGenerator
CreateElementGenerator(string root
);
251 // /// Creates a generator for a collection.
253 // /// <param name="root">The root expression.</param>
254 // /// <returns></returns>
255 // IJSCollectionGenerator CreateCollectionGenerator(string root);