Namespace: web

gpf. web

Root namespace for web-related tools (even if not in a browser)

Since:
  • 0.1.5

Methods


<static> createTagFunction(nodeName)

Create a tag generation function

Parameters:
Name Type Description
nodeName String

tag name. May include the namespace prefix svg for SVG elements

Since:
  • 0.2.1
Returns:

The tag generation function

Type
gpf.typedef.tagFunc
Examples

Tree building to string

var div = gpf.web.createTagFunction("div"),
    span = gpf.web.createTagFunction("span"),
tree = div({className: "test1"}, "Hello ", span({className: "test2"}, "World!"));
// tree.toString() gives <div class="test1">Hello <span class="test2">World!</span></div>

Tree building to DOM

var mockNode = mockDocument.createElement("any"),
    div = gpf.web.createTagFunction("div"),
    span = gpf.web.createTagFunction("span"),
    tree = div({className: "test"}, "Hello ", span("World!")),
    result = tree.appendTo(mockNode);

SVG building

var mockNode = mockDocument.createElement("any"),
    svgImage = gpf.web.createTagFunction("svg:image"),
    tree = svgImage({x: 0, y: 0, "xlink:href": "test.png"}),
    result = tree.appendTo(mockNode);