UNPKG

sbis3-node-ws

Version:

Модуль позволяет использовать ядро интерфейсного фреймворка sbis3-ws(`core.js`) и модуль работы с данными (`Source.js`) в приложении на nodejs.

97 lines 4.6 kB
define('js!Core/tmpl/js/astModules/partial', [ 'js!Core/tmpl/js/helpers/State', 'js!Core/tmpl/js/helpers/injectedDataForce', 'js!Core/tmpl/js/helpers/processExpressions', 'js!Core/tmpl/js/helpers/entityHelpers', 'js!Core/tmpl/js/helpers/errorHandling' ], function partialLoader(State, injectedDataForce, processExpressions, entityHelpers, errorHandling) { 'use strict'; var partialM = { parse: function partialParse(tag) { var tagData = tag.children; function resolveInjectedData(state, tag, injectingData) { if (injectingData) { this.traversingAST(injectingData, tag.key).when( function dataTraversing(tagDataAst) { tag.injectedData = tagDataAst; state.keep(tag); }.bind(this) ); } else { state.keep(tag); } return state; } function resolveInjectedTemplate(tag, state, tagData) { var template = tag.attribs.template.data; tag.injectedTemplate = template[0]; state = resolveInjectedData.call(this, state, tag, tagData); return state.promise; } function resolveTemplate(tag, state, tagData) { var template = tag.attribs.template.data.value.trim(); if (this.includeStack[template] === undefined) { errorHandling('Requiring tag for "' + template + '" is not found!', this.filename); } this.includeStack[template].when( function partialInclude(modAST) { if (modAST) { tag.children = modAST; state = resolveInjectedData.call(this, state, tag, tagData); } else { state.break('Requiring tag for "' + template + '" is not found!'); } }.bind(this), function brokenPartial(reason) { errorHandling(reason, this.filename); } ); return state.promise; } function resolveStatement() { var state = State.make(), attribs = this._traverseTagAttributes(tag.attribs); if (attribs.template === undefined) { errorHandling("No template tag for partial " + tag.name, this.filename); } tag.attribs = attribs; if (attribs.template.data.length > 0) { return resolveInjectedTemplate.call(this, tag, state, tagData); } return resolveTemplate.call(this, tag, state, tagData); } return function partialResolve() { return resolveStatement.call(this); }; }, module: function partialModule(tag, data) { var key = tag.prefix ? tag.prefix + '-' + tag.key : tag.key; function prepareScope(tag, data) { return injectedDataForce.call(this, { children: tag.injectedData, attribs: tag.attribs }, data); } function resolveStatement() { var assignModuleVar, preparedScope = prepareScope.call(this, tag, data); if (tag.injectedTemplate) { assignModuleVar = processExpressions(tag.injectedTemplate, data, this.calculators, this.filename, this.filename); if (assignModuleVar) { if (entityHelpers.isControlClass(assignModuleVar)) { var control = [entityHelpers.createControlNode(assignModuleVar, preparedScope.key || key)]; return this._process(control, preparedScope, key); } if (entityHelpers.isFunction(assignModuleVar)) { return assignModuleVar(preparedScope, key); } return this._process(assignModuleVar, preparedScope, key); } errorHandling('Your template variable by the name of "' + tag.injectedTemplate.name.string + '" is empty', this.filename); } return this._process(tag.children, preparedScope, key); } return function partialResolve() { return resolveStatement.call(this); }; } }; return partialM; });