Skip to content

0.2.1 Templates

Ivan S Glazunov edited this page Feb 20, 2015 · 2 revisions

import Templates = require('osws-templates');

.isSync

(argument: any) => boolean;

Templates.isSync(asSync(function() {})); // true;
Templates.isSync(asAsync(function(callback) {})); // false;
Templates.isSync(function(callback, other) {}); // false;
Templates.isSync(function(any, args) {}); // false;

.isAsync

(argument: any) => boolean;

Templates.isAsync(asSync(function() {})); // false;
Templates.isAsync(asAsync(function(callback) {})); // true;
Templates.isAsync(function(callback, other) {}); // false;
Templates.isAsync(function(any, args) {}); // false;

.asSync

(argument: Function) => Function;

Add to argument function, option: .__templatesSync = true;.

.asAsync

(argument: Function) => Function;

Add to argument function, option: .__templatesAsync = true;.

.dataRender

(data: TData, callback: TCallback) => void;

The method of synchronous/asynchronous conversion TData in string values. Is used when rendering.

.wrapMethod

(instance: Prototype, method: Function) => Function;

Adds a method options __templatesInstance as reference to an instance of the Prototype.

.regExpSearch

(data: string, reg: RegExp) => string[][];

._selectorRegExp

RegExp

TSelector RegExp

.parseSelector

(_attributes: IAttributes, selector: TSelector) => void;

Parse selector to IAttributes format.

All sended attributes overlap, not added. Exception - classes as .class-name-1.class-name-2, are added, do not overlap.

._stringTemplate

(string: string, context: Object, callback: TCallback) => void;

By default - wrap around method _.template.

var context = {
	type: 'name',
	data: asAsync(function(callback) { callback('Example'); }),
	person: {
		age: function() { return 100; },
		whose: asSync(function() { return 'my'; })
	}
};
Templates._stringTemplate('<%= person.whose %> <%= type %>: <%= name %>, age: <%= person.age() %>', context, console.log);
// my name: Example
You can override this method of their own
Templates._stringTemplate = function(string, context, callback) {
	callback(string);
}
Clone this wiki locally