-
Notifications
You must be signed in to change notification settings - Fork 0
0.2.7 Templates
import Templates = require('osws-templates');
(content: string, filename: string) => exports;
Only Node.js!
console.log(Templates._jsContentRequire('module.exports = __filename;', 'test.js')) // __dirname + 'test.js'
(content: string, filename: string) => Module;
Only Node.js!
var m = Templates.includeString('module.exports = "<%= name %>";', 'test.js');
m.render({ name: 'test' }, function(result) {
console.log(result); // 'test'
});
Only Node.js!
module.exports = __filename;
var mAsync = Templates.include('test.js', function(m) {
m.render({ name: 'test' }, function(result) {
console.log(result); // 'test'
});
});
mAsync(function(result) {
console.log(result); // 'test'
});
(filename: string) => Module;
Only Node.js!
module.exports = __filename;
Templates.includeSync('test.js').render({ name: 'test' }, function(result) {
console.log(result); // 'test'
});
(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;
(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;
(argument: Function) => Function;
Add to argument
function, option: .__templatesSync = true;
.
(argument: Function) => Function;
Add to argument
function, option: .__templatesAsync = true;
.
The method of synchronous/asynchronous conversion TData in string values. Is used when rendering.
(instance: Prototype, method: Function) => Function;
Adds a method options __templatesInstance
as reference to an instance of the Prototype.
(data: string, reg: RegExp) => string[][];
RegExp
(_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.
(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
Templates._stringTemplate = function(string, context, callback) {
callback(string);
}
(reconstructor: (...arguments: IArguments) => any) => Templates.Mixin
Mixin have to return something, otherwise it will be considered empty.
var mixin = Templates.mixin;
var mix = mixin(function(a, b, c) {
return div({ a: a })(b, div()(c));
});
mix instanceof Templates.Mixin // true
mix(1,2,3).render(console.log);
<div a="1">2<div>3</div></div>
Object with hash contains all tag and doctype implementation, methods content and mixin.
- TData: Renderer|sync|async|Mixin
- TCallback: (error, result) => void
- TSelector: string
- TInjector: () => void
- TAttributes: [name: string]: TData
- TContext: TData
Node.js:
var T = require('oswst');
Require.js:
define(['oswst'], function(T) {});
window
:
var T = window.oswst(_, async);
-
Templates
- .compile
- .include
- .render
- .renderContext
- .renderAttributes
- .renderSelector
- .sync
- .isSyncFunction
- .async
- .isAsyncFunction
- .Prototype()
- .Renderer > .Prototype
- .Data > .Renderer
- .data > .Data
- .Tag > .data
- .Single > .Tag
- .singles[string]
- .Double > .Tag
- .doubles[string]
- .Doctype > .Tag
- .doctypes[string]
- .xml > .Tag
- .Mixin > .Data
- .mixin > .Mixin
- .mixins[string]
- .Module > .Renderer
- .with