Class: ContentElement

ContentElement

new ContentElement(group, view, parser, renderer)

The ContentElement represents "content" parts of a view; it may itself contain one or more ContentElements. This class holds the name of the content-field (used via the yield-tag in the layouts: content, header, footer, dialogs, ...) and its definition as HTML-String.
Name Type Description
group Array | Object an array or object with properties name {String}, and content {String}
view Object the view that owns this ContentElement-element
parser mmir.parser.ParserUtils for the the content (optional) if supplied this object must have a function parse({String}) (see templateParseUtil)
renderer mmir.parser.RenderUtils for the the content (optional) if supplied, a parser must also be supplied; the renderer must have a function parse({String}) (see templateRenderUtil)

Members

private_parentContentElement

the parent ContentElement, if this is a sub-ContentElement to another ContentElement NOTE: this field will only be present, if the ContentElement is initialized from parsing a template (i.e. not present when restored for persisted JS view)

privateallArray.<mmir.parser.ParsingResult>

create ALL array and sort it, i.e. for localizations etc. ...

privateparentOffsetNumber

The offset of the ContentElement's raw String-content in relation to its parent ContentElement.

I.e. only when ContentElements are nested with other ContentElements.

For nested ContentElements, the offset always refers to outermost ContentElement, e.g.

  content
  ContentElement_1
  	ContentElement_2.parentOffset: offset to ContentElement_1
  		...
  			ContentElement_i.parentOffset: offset to ContentElement_1

privateparsingResultmmir.parser.ParsingResult

The ParsingResult that represents this ContentElement

private,constantSUB_ELEMENT_NAME

dummy name, if the ContentElement does not have a name: only ContentElements that represent Views and Partials have names - other sub-elements (@if,@for etc) do not have their own name/identifier. TODO externalize as constant

Methods

privatecheckHasDynamicContent()

HELPER check if a ContentElement has "dynamic content"

privatecreateJSEvalCode(strFuncBody, strFuncName){PlainObject}

HELPER: this creates function-code for embedded JavaScript code: using a function pre-compiles codes - this avoids (re-) parsing the code (by the execution environment) each time that the template is rendered.
Name Type Description
strFuncBody String the JavaScript code for the function body
strFuncName String the name for the function
Returns:
Type Description
PlainObject an object with the function-code with one input argument (see DATA_NAME) and the function ID/name: {func: STRING, funcName: STRING}

privatecreateJSEvalFunction(funcList, templateVars){function}

HELPER: this creates the initialize-function for the generated script-eval functions which will be attached to initEvalFunctions. The init-function embeds all variables with their "clear name" (i.e. without prefix @) so that these can be referenced from within the javascript code (i.e. functions in funcList) without additional modifications. When the init-function is invoked, it will set the generated functions to their corresponding ParsingResult in allContentElements. In addition 2 functions are attached to the ContentElement itself: setRenderData(data): this function must be called with the current render-data, each time before rendering the ContentElement exportRenderData(data): this function will export the current render-data to the data-argument. This function can be used to retrieve the possibly modified data after rendering.
Name Type Description
funcList Array.<GenFunc> the list of generated functions, where each entry has the form { index: Integer: the index of the ParsingResult that contains the function in field allContentElements funcName: String: the name of the function in its ParsingResult code: the function-code as generated by createJSEvalCode }
templateVars Array.<VarReference> the list of template variables (i.e. ParsingResult that encapsules a VarReference)
Returns:
Type Description
function the function that initializes

privategetAllVars(){Array.<VarReference>}

HELPER: get a list of VarReference ParsingResults from this ContentElement and all its parent ContentElements (i.e. all VarReferences that this ContentElement may "need to know about" in order to execute JavaScript code, e.g. template ScriptStatements like @())
Returns:
Type Description
Array.<VarReference> list of VarReference ParsingResults from this ContentElement and all its parent ContentElements

getController(){mmir.Controller}

Gets the controller for this ContentElement.
Returns:
Type Description
mmir.Controller the Controller of the owning view
Deprecated
See:
Returns:
Type Description
String the raw text from which this content element was parsed
Returns:
Type Description
Number the end position for this content Element within #getRawText
Gets the name of a mmir.ContentElement object (content, header, footer, dialogs, ...).
Returns:
Type Description
String Name - used by yield tags in layout
See:
Returns:
Type Description
String the raw text from which this content element was parsed
Returns:
Type Description
Number the start position for this content Element within #getRawText

getView(){mmir.View}

Gets the owner for this ContentElement, i.e. the mmir.View object.
Returns:
Type Description
mmir.View the owning View

hasDynamicContent(){Boolean}

Returns:
Type Description
Boolean returns true if this ContentElement conatains dynamic content, i.e. if it needs to be "evaluated" for rendering (otherwise, its plain text representation can be used for rendering)

privateisVarInList(varList, varName){Boolean}

HELPER: check whether a var-reference is already present
Name Type Description
varList Array.<VarReference>
varName String the name for the variable (if it starts with "@", it will be removed before checking)
Returns:
Type Description
Boolean true if varName corresponds to one of the VarReference entries in varList

privatesortAscByStart()

HELPER sorting function -> sort elements by occurrence in raw template text
create a String representation for this content element.
Returns:
Type Description
String the string-representation
Gets the definition of a mmir.ContentElement object. TODO remove this?
Returns:
Type Description
String The HTML content.

toStrings(renderingBuffer, data){Array.<String>}

Renders this object into the renderingBuffer.
Name Type Description
renderingBuffer Array of Strings (if null a new buffer will be created)
data Any (optional) the event data with which the rendering was invoked
Returns:
Type Description
Array.<String> of Strings the renderingBuffer with the contents of this object added at the end

privateunifyVarList(varList, rawText){Array.<VarReference>}

HELPER: get a list of VarReference ParsingResults from this ContentElement and all its parent ContentElements (i.e. all VarReferences that this ContentElement may "need to know about" in order to execute JavaScript code, e.g. template ScriptStatements like @())
Name Type Description
varList Array.<VarReference>
rawText String optional NOTE: if the list contains var-references from parsed JS-text, then the actual var-name must be extracted from the rawText (if necessary, the extracted var-name will be attached to the VarReference) can be omitted, if no VarReference entries in varList originate for parsing JS-content (i.e. renderer.parseJS())
Returns:
Type Description
Array.<VarReference> list of VarReference ParsingResults from this ContentElement and all its parent ContentElements