Skip to main content
Version: 1.2.x

View Engine

The viewEngine module provides information to the viewLocator module which is used to locate the view's source file. The viewEngine also transforms a view id into a view instance.

Here are the basic properties and functions:

  • viewExtension - The file extension that view source files are expected to have.
  • viewPlugin - The name of the RequireJS loader plugin used by the viewLocator to obtain the view source. (Use requirejs to map the plugin's full path).
  • overridable function isViewUrl(potential):bool - Returns true if the potential string is a url for a view, according to the view engine.
  • overridable function convertViewUrlToViewId(url):string - Converts a view url into a view id.
  • overridable function convertViewIdToRequirePath(viewId):string - Converts a view id into a full RequireJS path.
  • overridable function parseMarkup(markup):domElement - Parses some markup and turns it into a dom element.
  • overridable function createView(viewId):promise - Returns a promise for a dom element identified by the viewId parameter.

Note: View engines are expected to be written as RequireJS loader plugins so that the view "compilation" can be done both in the browser at debug time, and as part of the optimization process. To create a custom view engine, you implement it according to RequireJS specifications for a loader plugin, then in your main module you require the viewEngine module and set it's viewExtension and pluginPath variables to point to your implementation. By default, the text plugin is used to load standard html views.