]>
git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-ckeditor-component.git/blob - sources/core/template.js
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
7 * @fileOverview Defines the {@link CKEDITOR.template} class, which represents
8 * an UI template for an editor instance.
12 var rePlaceholder
= /{([^}]+)}/g;
15 * Lightweight template used to build the output string from variables.
17 * // HTML template for presenting a label UI.
18 * var tpl = new CKEDITOR.template( '<div class="{cls}">{label}</div>' );
19 * alert( tpl.output( { cls: 'cke-label', label: 'foo'} ) ); // '<div class="cke-label">foo</div>'
22 * @constructor Creates a template class instance.
23 * @param {String} source The template source.
25 CKEDITOR
.template = function( source
) {
27 * The current template source.
30 * @member CKEDITOR.template
33 this.source
= String( source
);
37 * Processes the template, filling its variables with the provided data.
40 * @member CKEDITOR.template
41 * @param {Object} data An object containing properties whose values will be
42 * used to fill the template variables. The property names must match the
43 * template variables names. Variables without matching properties will be
45 * @param {Array} [buffer] An array that the output data will be pushed into.
46 * The number of entries appended to the array is unknown.
47 * @returns {String/Number} If `buffer` has not been provided, the processed
48 * template output data; otherwise the new length of `buffer`.
50 CKEDITOR
.template
.prototype.output = function( data
, buffer
) {
51 var output
= this.source
.replace( rePlaceholder
, function( fullMatch
, dataKey
) {
52 return data
[ dataKey
] !== undefined ? data
[ dataKey
] : fullMatch
;
55 return buffer
? buffer
.push( output
) : output
;