SuperScript

This documentation is still being written. Please bear with us while we complete this documentation.

Emitter Bundles

The case may arise where more than one emitter is being emitted in the same fashion. For example, SuperScript.ExternalFile offers writing an emitter's output to an external file (and referencing this file on the webpage): bundling emitters allows multiple emitters to have their declarations processed as normal, and then compiled together via a shared final emitter.

It is important to remember that because an EmitterBundle is made up of standard emitters, the emitted declarations will still be processed by their individual emitters in the normal way; the concatenated output of each emitter in the bundle is then processed by the EmitterBundle.

EmitterBundle Members

Name Type Description
CustomObject object

This property allows the user to pass any required object through the modification and conversion process.

EmitterKeys IEnumerable<string>

Gets or sets the Key for each IEmitter in the bundle.

Emitters IEnumerable<IEmitter>

Gets a collection of instances of IEmitter which should have their emitted outputs bundled together.

Key string The identifier for this instance of IEmitter.
PostModifiers ICollection<CollectionPostModifier>

The implementations of CollectionPostModifier which have been assigned to this IEmitter.

HtmlWriter HtmlWriter

The implementation of HtmlWriter which has been assigned to this IEmitter for writing the formatted output to the webpage.

ToHtmlString IHtmlString

When called, this method emits the client-side form of the specified declarations via their specified instances of IEmitter.

As can be seen, an EmitterBundle doesn't expose the same members that an IEmitter offers; an IEmitter should still be configured to process declarations in a specific declaration-oriented manner. An EmitterBundle allows one or more CollectionPostModifier objects - for example, for minification purposes (it makes sense to minify the bundled output of multiple emitters in a single pass).

Also, instances of IEmitter are added to a bundle by specifying the Key of that IEmitter, not by adding the IEmitter itself to the Emitters property.

Configuring an Emitter Bundle

Configuring an EmitterBundle requires that the referenced instances of IEmitter have already been created.

Just as with an IEmitter, an EmitterBundle can be created in the configuration file or in code.

                        <configSections>
                            <section name="superScript" type="SuperScript.Configuration.SuperScriptConfig, SuperScript.Common, Version=0.0.0.1, Culture=neutral" />
                        </configSections>
                        

                        …
                        

                        <superScript>
                            <emitterBundles>
	                            <emitterBundle key="bundled" bundleKeys="javascript, whenReady, templates">
		                            <postModifiers>
			                            <modifier emitMode="LiveOnly" type="SuperScript.JavaScript.Modifiers.Post.JavaScriptMinifier, SuperScript.JavaScript" />
		                            </postModifiers>
		                            <writers>
			                            <modifier type="SuperScript.ExternalFile.Modifiers.Writers.ExternalScriptWriter, SuperScript.ExternalFile">
				                            <properties>
					                            <property name="Longevity" value="Reuse" type="SuperScript.Longevity, SuperScript.ExternalFile" />
				                            </properties>
			                            </modifier>
		                            </writers>
	                            </emitterBundle>
                            </emitterBundles>
                        </superScript>
                    

The above example requires the SuperScript.Common as well as additional libraries.

This example creates an EmitterBundle with the Key "bundled", and which incorporates instances of IEmitter whose Keys are "javascript", "whenReady" and "templates".

This EmitterBundle implements JavaScriptMinifier as a PostModifier, and then ExternalScriptWriter as the HtmlWriter.

The same EmitterBundle may also be declared in code.

                        EmitterBundles.Add(new EmitterBundle
					                           {
						                           Key = "bundled",
						                           EmitterKeys = new List<string>
										                             {
												                         "javascript",
											                             "whenReady",
											                             "templates"
										                             },
						                           PostModifiers = new Collection<CollectionPostModifier>
											                           {
													                        new JavaScriptMinifier
														                        {
															                        EmitMode = EmitMode.LiveOnly
														                        }
											                           },
						                           HtmlWriter = new ExternalScriptWriter
											                        {
												                        Longevity = Longevity.Reuse
										                            }
					                           });
                    

How to Emit an EmitterBundle

An EmitterBundle is emitted in exactly the same way as an IEmitter.

Read the documentation for emitting an IEmitter here.

What Next?

Read about declarations here.