/tempart

Templating with possibility to compile only a part of it

Primary LanguageTypeScriptMIT LicenseMIT

tempart Build Status Coverage Status

Its a mustache templating engine, which is optimized for recompiling. The precompiler returns a tree of blocks with there dependencies

api 0.4

{{variable}} when only a variable should be displayed
{{#if variable}} when an mustache helper gets called
<Partial some="arguments" /> an subtemplate can rendered too
{{#if object.property && functionName(variableName, anotherVariable)}}
	<Logo newName=variableName computedName=functionName(anotherVariable, variableName, "logo")>
{{/if}}
// This is the generated JSON which got generated, by the upper mustache template
// This JSON will get used by the compiler for generating html dynamicly
[{
	// calls tempartCompiler.types.if
	type: 'if',

	// Identifier of this block, generated by precompiler
	id: 1,

	// Constants used for this block
	constants: ['&&'],

	// parameters for which tempartCompiler.types.if gets called
	parameters: [{
		// calls tempartCompiler.execs.variables( block, parameterBlock, globalScope, localScope)
		// block is {type: 'if', id: 1, ...}
		// parameterBlock is {exec: 'variables', value: 0}
		// globalScope is the contentBlock of the controller
		// localScope are the local rewrites, variables which are only used for the template (e.g. index of an for)
		exec: 'variable'

		// tempartCompiler.execs.variables looks in block.variables[0] the key, first in localScope, then in globalScope
		value:['object', 'property'],
	}, {
		// calls tempartCompiler.execs.callee( block, parameterBlock, globalScope, localScope)
		exec: 'callee',

		// this will get called: controller.functionName(variableName, anotherVariable)
		value: 'functionName',

		// These parameters get called from inside the tempartCompiler.execs.callee, via tempartCompiler.helpers.getParameters (not recursive)
		parameters: [{
			exec: 'variable',
			value: ['anotherVariable']
		}, {
			exec: 'variable',
			value: ['variable']
		}, {
			exec: 'constant',
			value: ['logo']
		}]
	}],
	// Contains is an array of new blocks, which are inside the current block
	children: [{
		type: 'partial',
		id: 0,
		parameters: [{
			exec: 'constant',
			value: ['logo']
		}, {
			exec: 'vaiable',
			// name is the used variableKey for the variableValue
			name: 'newname',
			value: ['variableName']
		}, {
			exec: 'callee',
			name: 'computedName',
			value: 'functionName'
			parameters: [{
				exec: 'variable',
				value: ['variableName']
			}, {
				exec: 'variable',
				value: ['anotherVariable']
			}, {
				exec: 'constant',
				value: ['logo']
			]
		}],
	}]
}]