npm.io
3.0.0 • Published 10 years agoCLI

taya

Licence
MIT
Version
3.0.0
Deps
2
Vulns
0
Weekly
0

Taya

Presentation

Taya is a JavaScript fast and beautiful engine.

Here is an example.

@each (user in users)
	{ user.name }

	@if (user.publishEmail)
		{ user.email }
	@end
@end

Syntax

The syntax is very simple.

Condition
@if (condition)

@elif (anotherCondition)

@else

@end
@unless (condition)

@else

@end
Foreach loop
@each (value in list)
	{ value.thing }
@end
Execute
@execute (result = 'test')
Print
{ Math.random() }
Escape
!@escaped
!{ also }

API

First, install the NPM package: npm install taya

Taya

The Taya class represents a template.

import Taya from 'taya';

let template = new Taya('{{ hello }}');
Taya#render([context, escape])

Renders a Taya template with a context, and the escape function.

By default, context is an empty object, and escape is an HTML escape function.

import Taya from 'taya';

let template = new Taya('{{ hello }}');

template.render({
	hello: 'Hello World'
}) === 'Hello World';
Taya.render(source, [context, escape])

Render a taya source with a context and an escape function. See above for the parameters.

Taya.renderFile(path, [context, escape])

Renders a taya file (use a cache) and return a promise. See above for context and escape parameters.

import Taya from 'taya';

Taya.renderFile('test.tay').then(function(result) {
	console.log(result);
});

Keywords