lb.base.template.html

Base Module for HTML Templates

This module defines filter functions for HTML templates, for use with lb.base.template.applyFilters(input...,filters):any in the base template module.

HTML filters are applied to DOM nodes, which get modified in place.  In order to keep the original template for reuse with a different set of values, the node should be cloned before HTML filters are applied.

Authors

Copyright

Eric Bréchemier © 2011-2013, Some Rights Reserved Legal-Box SAS © 2010-2011, All Rights Reserved

License

BSD License http://creativecommons.org/licenses/BSD/

Version

2013-09-10

Summary
lb.base.template.htmlBase Module for HTML Templates
Functions
topDownParsing(node[,context...],filters)Apply filters recursively to attributes and child nodes.
replaceParams(getValue): functionGet a filter function to replace parameters in attribute and text nodes.

Functions

topDownParsing(node[,context...],filters)

Apply filters recursively to attributes and child nodes.

The attributes are processed first (the order is browser-dependent), then child nodes are processed in a depth-first recursion.

Parameters

nodeDOM Node, a DOM node.  Only elements are processed by this filter, other nodes are left untouched.
context...any, optional, variable number of parameters providing context to the transformation.  All context arguments are forwarded in recursive calls to applyFilters().
filtersarray of functions, the list of filter functions to be applied recursively.  This argument is required and always last, which allows filter functions applied to any number of context arguments to omit it in their declaration.

Note

In Internet Explorer, lots of attribute nodes are present with a default value.  Only attributes explicitly defined in the document or through JavaScript are processed: attributes that do not have ‘specified’ property set to true are ignored.

Reference

specifiedInterface Attr http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-637646024

replaceParams(getValue): function

Get a filter function to replace parameters in attribute and text nodes.

This method applies replaceParams() from the base string templates module, and follows the same conventions:

  • parameters to replace are surrounded by ‘#’ characters
  • getValue() is called for replacement values

See details of parameter format in lb.base.template.string.replaceParams(getValue): function.

Parameter

getValuefunction, a getter function returning values for the replacement of parameters:
function(name): any

The name argument is the name of the parameter to replace.  The getter value should return string values when a matching property is found, and null otherwise.

Returns

  • function, a closure wrapped around the given getter function, with the following signature:
Function: filter(htmlNode)
Replace parameters in attribute and text nodes
with corresponding values returned by getValue().

The replacements are operated in place in given node.

Parameters:
  htmlNode - DOM Node, a DOM node. Only attribute and text nodes
             are considered for parameter replacement.
             Other nodes are left untouched.
  • null when the required getter argument is missing or not a function
Apply filters successively to input made of preceding arguments.
Get a filter function to replace parameters in a string template.
Close