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
.Generic
;
25 public interface IJSCodeGenerator
28 /// Gets the main JS generator.
30 /// <value>The JS generator.</value>
31 IJSGenerator JSGenerator { get; set; }
34 /// Gets or sets the URL helper.
36 /// <value>The URL helper.</value>
37 IUrlBuilder UrlBuilder { get; set; }
40 /// Gets or sets the server utility.
42 /// <value>The server utility.</value>
43 IServerUtility ServerUtility { get; set; }
46 /// Gets or sets the engine context.
48 /// <value>The engine context.</value>
49 IEngineContext EngineContext { get; set; }
52 /// Gets the extensions.
54 /// <value>The extensions.</value>
55 IDictionary
<string, object> Extensions { get; }
58 /// Calls the specified function with the optional arguments.
62 /// The following example uses nvelocity syntax:
65 /// $page.call('myJsFunctionAlreadyDeclared', '10', "'message'", $somethingfrompropertybag, $anothermessage.to_squote)
73 /// myJsFunctionAlreadyDeclared(10, 'message', 1001, 'who let the dogs out?')
78 /// <param name="function">The function name.</param>
79 /// <param name="args">The arguments.</param>
80 void Call(object function
, params object[] args
);
83 /// Writes the content specified to the generator instance
87 /// This is for advanced scenarios and for the infrastructure. Usually not useful.
90 /// <param name="content">The content.</param>
91 void Write(String content
);
94 /// Outputs the content using the renderOptions approach.
96 /// If the renderOptions is a string, the content is escaped and quoted.
99 /// If the renderOptions is a dictionary, we extract the key <c>partial</c>
100 /// and evaluate the template it points to. The content is escaped and quoted.
103 /// <param name="renderOptions">The render options.</param>
104 /// <returns></returns>
106 /// The following example uses nvelocity syntax:
108 /// $page.Call('myJsFunction', $page.render("%{partial='shared/newmessage.vm'}") )
114 /// myJsFunction('the content from the newmessage partial view template')
117 object Render(object renderOptions
);
120 /// Writes the content specified to the generator instance
124 /// This is for advanced scenarios and for the infrastructure. Usually not useful.
126 /// <param name="content">The content.</param>
127 void AppendLine(String content
);
130 /// Records the specified line.
132 /// <param name="line">The line.</param>
133 void Record(string line
);
136 /// Builds the JS arguments.
138 /// <param name="args">The args.</param>
139 /// <returns></returns>
140 string BuildJSArguments(object[] args
);
143 /// Replaces the tail from the current line (usually a ';') by period.
145 void ReplaceTailByPeriod();
148 /// Removes the tail from the current line (usually a ';')
153 /// Gets the js lines.
155 /// <value>The js lines.</value>
156 StringBuilder Lines { get; }
159 /// Dump the operations recorded so far as javascript code.
162 /// <returns></returns>