index Zimbu documentation

MODULE ZUT @public

summary

     

Zimbu Templates. For creating interactive web pages.

ALIAS  TextDialog @public 
CLASS  EventConfig @public  The configuration for events handled by ZUT.
CLASS  Context @public  The context for processing ZUT templates.
ALIAS  HtmlFunc @public  The type used for a ZUT template method producing HTML.
CLASS  Page @public  The properties of an HTML page.
CLASS  DomElement @public  Lowest level object, an HTML element.
CLASS  DomEvent @public  A low level browser event.
CLASS  Element @public  A wrapper around an HTML element.
ENUM  EventType @public 
CLASS  Controller @public  All controllers should inherite from this.
CLASS  Event @public  The properties of an event.
INTERFACE  I_Listener @public  An interface which is used to pass information from a Controller to the object that created the DOM.
CLASS  Timer @public  A Timer is used to postpone a callback to be invoked. The Timer fires once. To trigger multiple times use an Interval.
CLASS  E_BadValue @file  Exception thrown when using a value in a way the result can't possibly be valid.
CLASS  Html @public  A string that is properly formatted HTML.
CLASS  Attributes @public  A string that is properly formatted HTML attributes.
CLASS  Url @public  A string that is a properly formatted URL.
CLASS  Css @public  A string that is properly formatted CSS.
CLASS  Javascript @public  A string that is properly formatted Javascript.
 
callOnLoad(method) @public  Add a method to be invoked after the HTML page has loaded.
getElementById(id) ZUT.Element @public  Finds element id.
appendToDom(html, blockStyle) ZUT.Element @public  Append html to the DOM.
appendToDom(template, blockStyle) ZUT.Element @public  Append the result of template to the DOM.
addCss(name, css) @public  Add a CSS style element to the document.
fillElement(id, template) @public  Fill element id with the result of template.
setDisplay(id, display) @public  Set the display attribute of element id.
getDisplay(id) bool @public  Returns wether element id is being displayed.
getRadioValue(name) string @public  Returns the value of the selected radio button of the group name
getValue(name) string @public  Returns the value of the first input with name
getLocation() IO.Url @public  Returns the location of the current page.
navigate(url) @public  Navigate to url.
createPage(httpContext, page) string @public  Function passed to a FunctionServlet to create the HTML page.
controllerName(f) string @public  Gets the internal name of a controller.
registerAction(f) @public  Registers an action on a controller.
uid() string @public  Return a unique ID.
alert(message) @public  In the browser show an alert. In the server log a message.
throw(msg) @public 
htmlTextEscape(text) string @public  Returns text conservatively HTML-escaped.
htmlEscape(text) string @public  Returns text HTML-escaped.
htmlUnescape(text) string @public  Returns text HTML-un-escaped.
htmlDataHtmlEscape(htmlText) string @public  Returns htmlText HTML-data-escaped.
htmlDataStringEscape(text) string @public  Returns text HTML-data-escaped.
tagNameEscape(text) string @public  Returns text when it is a valid tag name.
attributesEscape(text) string @public  Returns text Attributes-escaped.
attrValueEscape(text) string @public  Returns text Attribute-value-escaped.
attrValueEscape(url) string @public  Returns url Attribute-value-escaped.
attrNoSpaceEscape(text) string @public  Returns text Attribute-value-escaped for values not in quotes.
attrNoSpaceEscape(url) string @public  Returns url Attribute-unquoted-value-escaped.
urlEscape(text, isParamVal) string @file  Apply URL-escaping to a plain text URL.
urlParamValEscape(text) string @file  Apply URL-escaping to a plain text URL parameter value.
urlUnEscape(text) string @file  Turns all %xx pieces into the xx byte.
urlEscape(byte, isParamVal) string @file  Returns byte as a URL-escaped string.
cssEscape(text) string @public  Returns text and throws an error for missing quotes, "</", etc.
cssSingleStringEscape(text) string @public  Returns url CSS-string-escaped for single quotes.
cssDoubleStringEscape(text) string @public  Returns text Css-string-escaped for double quotes.
cssCommentEscape(text) string @public  Returns text Css-comment-escaped for a /* comment
cssCommentEscape(text) string @public  Returns text Css-comment-escaped for a /* comment
javascriptEscape(text) string @public  Returns text and throws an error for missing quotes, "</", etc.
javascriptSingleStringEscape(text) string @public  Returns url Javascript-string-escaped for single quotes.
javascriptSingleStringEscape(url) string @public  Returns url Javascript-string-escaped for single quotes.
javascriptDoubleStringEscape(text) string @public  Returns text Javascript-string-escaped for double quotes.
javascriptDoubleStringEscape(url) string @public  Returns url Javascript-string-escaped for double quotes.
javascriptRegexpEscape(text) string @public  Returns text Javascript-string-escaped for a regular expression.
javascriptRegexpEscape(url) string @public  Returns text Javascript-string-escaped for a regular expression.
javascriptLineCommentEscape(text) string @public  Returns text Javascript-comment-escaped for a // comment
javascriptLineCommentEscape(text) string @public  Returns text Javascript-comment-escaped for a // comment
javascriptBlockCommentEscape(text) string @public  Returns text Javascript-comment-escaped for a /* comment
javascriptBlockCommentEscape(text) string @public  Returns text Javascript-comment-escaped for a /* comment
 

members (alphabetically)

     

PROC addCss(string name, ZUT.Css css) @public

     

Add a CSS style element to the document.

When name is not NIL, the CSS will only be added when CSS with this name was not added before. The CSS blocks in templates use the file name here.

On the server the style will be added to the list of styles for the page. On the client the style will be added as a separate style element right away.

PROC alert(string message) @public

     

In the browser show an alert. In the server log a message.

FUNC appendToDom(ZUT.Html html, string blockStyle) ZUT.Element @public

     

Append html to the DOM.

If "stdout" was written to html will be put before it.

If blockStyle is not NIL the template output will be wrapped in a div with "display" set to blockStyle.

Can only be used in the client.

If blockStyle is NIL returns the first appended element. If nothing was appended then NIL is returned.

If blockStyle is not NIL returns the Element of the appended div.

FUNC appendToDom(ZUT.HtmlFunc template, string blockStyle) ZUT.Element @public

     

Append the result of template to the DOM.

If "stdout" was written to it will be put before it.

If blockStyle is not NIL the template output will be wrapped in a div with "display" set to blockStyle.

Can only be used in the client.

If blockStyle is NIL returns the first appended element. If nothing was appended then NIL is returned.

If blockStyle is not NIL returns the Element of the appended div.

FUNC attrNoSpaceEscape(string text) string @public

     

Returns text Attribute-value-escaped for values not in quotes.

As attrValueEscape() but also escapes white space.

FUNC attrNoSpaceEscape(ZUT.Url url) string @public

     

Returns url Attribute-unquoted-value-escaped.

Converts url to a string and then applies attrNoSpaceEscape() on it.

FUNC attrValueEscape(string text) string @public

     

Returns text Attribute-value-escaped.

As attributesEscape() but also escapes quotes.

FUNC attrValueEscape(ZUT.Url url) string @public

     

Returns url Attribute-value-escaped.

Converts url to a string and then applies attrValueEscape() on it.

FUNC attributesEscape(string text) string @public

     

Returns text Attributes-escaped.

Only escapes & and control characters.

PROC callOnLoad(proc<> method) @public

     

Add a method to be invoked after the HTML page has loaded.

If the page already loaded the method will be invoked right away.

To do this from a controller you can use the Init method:

SHARED
  FUNC Init() status
    GENERATE_IF Z.lang == "JS"
      ZUT.callOnLoad(onLoad)
    }
    RETURN OK
  }

FUNC controllerName(dyn f) string @public

     

Gets the internal name of a controller.

This is needed to uniquely identify zcontroller class names.

Normally the ZUT plugin generates these calls for you when it finds a "zcontroller" attribute.

The argument must be a class.

 ZUT.controllerName(ButtonController)

FUNC createPage(HTTP.Context httpContext, ZUT.Page page) string @public

     

Function passed to a FunctionServlet to create the HTML page.

FUNC cssCommentEscape(string text) string @public

     

Returns text Css-comment-escaped for a /* comment

FUNC cssCommentEscape(dyn text) string @public

     

Returns text Css-comment-escaped for a /* comment

FUNC cssDoubleStringEscape(string text) string @public

     

Returns text Css-string-escaped for double quotes.

FUNC cssEscape(string text) string @public

     

Returns text and throws an error for missing quotes, "</", etc.

FUNC cssSingleStringEscape(string text) string @public

     

Returns url CSS-string-escaped for single quotes.

PROC fillElement(string id, ZUT.HtmlFunc template) @public

     

Fill element id with the result of template.

Can only be used in the client.

FUNC getDisplay(string id) bool @public

     

Returns wether element id is being displayed.

When style.display is "none" FALSE is returned, otherwise TRUE.

When element id does not exist FALSE is returned.

Can only be used in the client.

FUNC getElementById(string id) ZUT.Element @public

     

Finds element id.

Returns NIL if the element is not found.

FUNC getLocation() IO.Url @public

     

Returns the location of the current page.

On the server this returns NIL.

FUNC getRadioValue(string name) string @public

     

Returns the value of the selected radio button of the group name

Returns NIL when no item with name can be found or none is selected.

FUNC getValue(string name) string @public

     

Returns the value of the first input with name

Returns NIL when no item with name can be found.

FUNC htmlDataHtmlEscape(string htmlText) string @public

     

Returns htmlText HTML-data-escaped.

Like htmlEscape but doesn't change & and line break.

FUNC htmlDataStringEscape(string text) string @public

     

Returns text HTML-data-escaped.

Like htmlEscape but doesn't change &.

FUNC htmlEscape(string text) string @public

     

Returns text HTML-escaped.

Besides what htmlTextEscape() does also replaces " with &quot;, ' with &#39; and a line break with <br>.

FUNC htmlTextEscape(string text) string @public

     

Returns text conservatively HTML-escaped.

Replaces & with &amp;, < with &lt;, > with &gt;, NUL with &#0;.

FUNC htmlUnescape(string text) string @public

     

Returns text HTML-un-escaped.

Unodes htmlEscape(), except that <br> is not changed back to a line break.

FUNC javascriptBlockCommentEscape(string text) string @public

     

Returns text Javascript-comment-escaped for a /* comment

FUNC javascriptBlockCommentEscape(dyn text) string @public

     

Returns text Javascript-comment-escaped for a /* comment

FUNC javascriptDoubleStringEscape(string text) string @public

     

Returns text Javascript-string-escaped for double quotes.

FUNC javascriptDoubleStringEscape(ZUT.Url url) string @public

     

Returns url Javascript-string-escaped for double quotes.

FUNC javascriptEscape(string text) string @public

     

Returns text and throws an error for missing quotes, "</", etc.

FUNC javascriptLineCommentEscape(string text) string @public

     

Returns text Javascript-comment-escaped for a // comment

FUNC javascriptLineCommentEscape(dyn text) string @public

     

Returns text Javascript-comment-escaped for a // comment

FUNC javascriptRegexpEscape(string text) string @public

     

Returns text Javascript-string-escaped for a regular expression.

FUNC javascriptRegexpEscape(ZUT.Url url) string @public

     

Returns text Javascript-string-escaped for a regular expression.

FUNC javascriptSingleStringEscape(string text) string @public

     

Returns url Javascript-string-escaped for single quotes.

FUNC javascriptSingleStringEscape(ZUT.Url url) string @public

     

Returns url Javascript-string-escaped for single quotes.

PROC navigate(IO.Url url) @public

     

Navigate to url.

This replaces the current page.

On the server this has no effect.

PROC registerAction(dyn f) @public

     

Registers an action on a controller.

This is needed for methods that are not called directly but only from the ZUT event handling implementation.

Normally the ZUT plugin generates these calls for you when it finds a "zaction" attribute.

The argument must be a method on a class, taking a ZUt.Event argument and return a bool: func<Event => bool>

 ZUT.registerAction(ButtonController.clicked)

PROC setDisplay(string id, bool display) @public

     

Set the display attribute of element id.

When display is TRUE then style.display is made empty. When display is FALSE then style.display is set to "none".

Can only be used in the client.

FUNC tagNameEscape(string text) string @public

     

Returns text when it is a valid tag name.

Throws an E_BadValue exception when text contains an invalid character or when text is empty.

Leading and trailing white space is removed first.

Also throws an E_BadValue exception for "script", "style" and "title", because these require different escaping.

PROC throw(string msg) @public

FUNC uid() string @public

     

Return a unique ID.

This will start with "z_" when used in the server, "z-" when used in the client.

FUNC urlEscape(string text, bool isParamVal) string @file

     

Apply URL-escaping to a plain text URL.

See below for what replacements are done.

When isParamVal is present and TRUE, then characters with a special meaning in a parameter value, such as "=" and "&", will also be escaped.

This assumes using UTF-8.

FUNC urlEscape(int byte, bool isParamVal) string @file

     

Returns byte as a URL-escaped string.

Returns the % form for a special character.

When isParamVal is present and TRUE, then characters with a special meaning in a parameter value, such as "=" and "&", will also be escaped.

Returns an empty string for a control character.

FUNC urlParamValEscape(string text) string @file

     

Apply URL-escaping to a plain text URL parameter value.

See below for what replacements are done. Additionally characters with a special meaning in a parameter value, such as "=" and "&", are escaped.

This assumes using UTF-8.

FUNC urlUnEscape(string text) string @file

     

Turns all %xx pieces into the xx byte.

license

      Copyright 2014 Bram Moolenaar All Rights Reserved.

      Licensed under the Apache License, Version 2.0. See the LICENSE file or obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0