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
.Configuration
18 using System
.Collections
.Generic
;
23 public class JSGeneratorConfiguration
25 private readonly List
<LibraryConfiguration
> libraries
= new List
<LibraryConfiguration
>();
26 private LibraryConfiguration defaultLibrary
;
31 /// <param name="name">The name.</param>
32 /// <param name="mainGenerator">The main generator.</param>
33 /// <returns></returns>
34 public LibraryConfigurationBuilder
AddLibrary(string name
, Type mainGenerator
)
36 LibraryConfiguration config
= new LibraryConfiguration(name
, mainGenerator
);
37 libraries
.Add(config
);
39 return new LibraryConfigurationBuilder(this, config
);
43 /// Gets the libraries configuration.
45 /// <value>The libraries.</value>
46 public List
<LibraryConfiguration
> Libraries
48 get { return libraries; }
52 /// Gets the default library configuration.
54 /// <value>The default library.</value>
55 public LibraryConfiguration DefaultLibrary
57 get { return defaultLibrary; }
61 /// Configures a JS generator for specific JS library
63 public class LibraryConfigurationBuilder
65 private readonly JSGeneratorConfiguration configuration
;
66 private readonly LibraryConfiguration config
;
67 private readonly ElementGeneratorConfigBuilder elementConfig
;
70 /// Initializes a new instance of the <see cref="LibraryConfigurationBuilder"/> class.
72 /// <param name="configuration">The configuration.</param>
73 /// <param name="config">The config.</param>
74 public LibraryConfigurationBuilder(JSGeneratorConfiguration configuration
, LibraryConfiguration config
)
76 this.configuration
= configuration
;
78 elementConfig
= new ElementGeneratorConfigBuilder(this);
82 /// Adds an extension.
84 /// <param name="extensionType">Type of the extension.</param>
85 /// <returns></returns>
86 public LibraryConfigurationBuilder
AddExtension(Type extensionType
)
88 config
.MainExtensions
.Add(extensionType
);
93 /// Sets the browser validator provider for the library
95 /// <param name="browserValidatorProvider">The browser validator provider.</param>
96 public LibraryConfigurationBuilder
BrowserValidatorIs(Type browserValidatorProvider
)
98 config
.BrowserValidatorProvider
= browserValidatorProvider
;
103 /// Gets the element generator.
105 /// <value>The element generator.</value>
106 public ElementGeneratorConfigBuilder ElementGenerator
108 get { return elementConfig; }
112 /// Sets this JS library as the default one.
114 public void SetAsDefault()
116 configuration
.defaultLibrary
= config
;
120 /// Configures the element section of the library config
122 public class ElementGeneratorConfigBuilder
124 private readonly LibraryConfigurationBuilder builder
;
127 /// Initializes a new instance of the <see cref="ElementGeneratorConfigBuilder"/> class.
129 /// <param name="builder">The builder.</param>
130 public ElementGeneratorConfigBuilder(LibraryConfigurationBuilder builder
)
132 this.builder
= builder
;
136 /// Adds an element only extension.
138 /// <param name="extensionType">Type of the extension.</param>
139 /// <returns></returns>
140 public ElementGeneratorConfigBuilder
AddExtension(Type extensionType
)
142 builder
.config
.ElementExtension
.Add(extensionType
);
147 /// Go back to the main library configuration
149 public LibraryConfigurationBuilder Done
151 get { return builder; }
158 /// Configuration for JS generation for an specific JS library
160 public class LibraryConfiguration
162 private readonly string name
;
163 private readonly Type mainGenerator
;
164 private readonly List
<Type
> mainExtensions
= new List
<Type
>();
165 private readonly List
<Type
> elementExtension
= new List
<Type
>();
166 private Type browserValidatorProvider
;
169 /// Initializes a new instance of the <see cref="LibraryConfiguration"/> class.
171 /// <param name="name">The name.</param>
172 /// <param name="mainGenerator">The main generator.</param>
173 public LibraryConfiguration(string name
, Type mainGenerator
)
175 if (string.IsNullOrEmpty(name
))
177 throw new ArgumentNullException("name");
179 if (mainGenerator
== null)
181 throw new ArgumentNullException("mainGenerator");
185 this.mainGenerator
= mainGenerator
;
191 /// <value>The name.</value>
198 /// Gets the main generator.
200 /// <value>The main generator.</value>
201 public Type MainGenerator
203 get { return mainGenerator; }
207 /// Gets the main extensions.
209 /// <value>The main extensions.</value>
210 public List
<Type
> MainExtensions
212 get { return mainExtensions; }
216 /// Gets the element extension.
218 /// <value>The element extension.</value>
219 public List
<Type
> ElementExtension
221 get { return elementExtension; }
225 /// Gets or sets the browser validator provider.
227 /// <value>The browser validator provider.</value>
228 public Type BrowserValidatorProvider
230 get { return browserValidatorProvider; }
231 set { browserValidatorProvider = value; }