JavaScript Extension Development API for Oracle Visual Builder Cloud Service - Classic Applications

Source: components.dt/js/spi/generators/Generator.js

define([], function() {

    'use strict';

    /**
     * A generator builds DOM tree element for the view it is registered for.
     * It plugs into the Abcs system using the component registration API
     * ({@link components.dt/js/api/ComponentProviderRegistry ComponentProviderRegistry}).
     *
     * <p>A component creator creates a topmost view for the component's
     * hierarchy and in order to be rendered on a page the view needs to be
     * transformed into a DOM element. That is the responsibility of a generator
     * when the Abcs infrastructure calls its {@link components.dt/js/spi/generators/Generator#buildView Generator.buildView}
     * method.</p>
     *
     * @AbcsExtension stable
     * @exports components.dt/js/spi/generators/Generator
     * @constructor
     * @private
     * @example <caption>How to build DOM elements for your views</caption>
     * define([], function () {
     *
     *     'use strict';
     *
     *     var MyViewGenerator = function() {
     *     };
     *
     *     MyViewGenerator.prototype.buildView = function (view, page) {
     *         var $element = $('<p>Hello i am your paragraph component</p>');
     *         return $element;
     *     };
     *
     *     return MyViewGenerator;
     * });
     * @see {@link components.dt/js/spi/generators/Generator#buildView Generator.buildView}
     * @see {@link pages.dt/js/api/ViewGeneratorSupport.buildElement ViewGeneratorSupport.buildElement}
     * for how to build and add elements for child views.
     * @see {@link pages.dt/js/api/ViewGeneratorSupport.applyProperties ViewGeneratorSupport.applyProperties}
     * for how to apply view properties to your HTML template.
     * @version 16.3.5
     *
     */
    var Generator = function() {
        AbcsLib.checkThis(this);
    };

    Generator._ERROR_NOT_IMPLEMENTED = 'Should be overridden in implementations. Have you mistyped "buildView" method name?';

    /**
     * Builds the view DOM tree and returns its jquery element.
     * <p>The method is called by the Abcs infrastructure when it needs the DOM
     * representation of the view to lay and render it on a page. The method is
     * expected to return a jQuery element with <strong>a single top element</strong>
     * wrapping the view's DOM structure.</p>
     *
     * @AbcsExtension stable
     * @version 16.3.5
     * @param {pages.dt/js/api/View} view view to build the DOM structure for.
     * @param {pages.dt/js/api/Page} page - the page the view belongs to
     * @returns {jQuery} jQuery element wrapping a single top DOM element
     * containing the complete view's hierarchical structure.
     * @see {@link components.dt/js/spi/generators/Generator Generator example}
     * @see {@link pages.dt/js/api/ViewGeneratorSupport.buildElement ViewGeneratorSupport.buildElement}
     * for how to build and add child views.
     * @see {@link pages.dt/js/api/ViewGeneratorSupport.applyProperties ViewGeneratorSupport.applyProperties}
     * for how to apply view properties to your HTML template.
     */
    Generator.prototype.buildView = function(/*view, page*/) {
        throw new Error(Generator._ERROR_NOT_IMPLEMENTED);
    };

    return Generator;

});