new mmir.view.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_contentVarsmmir.parser.ParsingResult
-
a list of VarReferences that are relevant/active for sub-content elements (e.g. content of FOR elements) NOTE: this field is only filled, if the ContentElement is created for parsing a template (i.e. not present when restored from a persisted JS view object).
-
privateallArray.<mmir.parser.ParsingResult>
-
create ALL array and sort it, i.e. for localizations etc. ...
-
protectedcommentsmmir.parser.ParsingResult
-
protecteddefinitionString
-
The "raw" template text.
-
protectedescapesmmir.parser.ParsingResult
-
protectedforsmmir.parser.ParsingResult
-
protectedhelpersmmir.parser.ParsingResult
-
protectedifsmmir.parser.ParsingResult
-
protectedlocalizationsmmir.parser.ParsingResult
-
List of the "localize" statements in the template.
-
protectedlocalizermmir.LanguageManager
-
the "localizer" i.e. for handeling internationalization / localized Strings
-
protectedparsermmir.parser.ParserUtils
-
-
protectedpartialsmmir.parser.ParsingResult
-
protectedrenderermmir.parser.RenderUtils
-
-
protectedscriptBlocksmmir.parser.ParsingResult
-
protectedscriptStatementsmmir.parser.ParsingResult
-
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
-
protectedviewmmir.view.View
-
-
protectedyields
-
NOTE by default this field is not added to the allContentElements list (i.e. will not be stored/stringified)
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 infuncList
) without additional modifications. When the init-function is invoked, it will set the generated functions to their corresponding ParsingResult inallContentElements
. 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 ContentElementexportRenderData(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 -
getName(){String}
-
Gets the name of a
mmir.view.ContentElement
object (content, header, footer, dialogs, ...).Returns:
Type Description String Name - used by yield tags in layout -
getView(){mmir.view.View}
-
Gets the owner for this ContentElement, i.e. the
mmir.view.View
object.Returns:
Type Description mmir.view.View the owning View -
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
ifvarName
corresponds to one of the VarReference entries invarList
-
privatesortAscByStart()
-
HELPER sorting function -> sort elements by occurrence in raw template text
-
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