Comparing version 1.0.0 to 2.0.0
@@ -5,2 +5,3 @@ "use strict"; | ||
var Node = require("./node"); | ||
var Safe = require("./safe"); | ||
var _context; | ||
@@ -60,2 +61,20 @@ | ||
/* | ||
* @safe | ||
* @description | ||
* Creates a safe string of html to be used as a child node. | ||
* ```javascript | ||
* // Using jsx. | ||
* const html = "<span></span>"; | ||
* const node = <body>{vdo.safe(html)}</body>; | ||
* String(node) //-> "<body><span></span></body>" | ||
* ``` | ||
* | ||
* @param {*} html - The html to mark as safe. | ||
* @returns {Safe} | ||
*/ | ||
vdo.safe = function (html) { | ||
return new Safe(html); | ||
}; | ||
/* | ||
* @static | ||
@@ -62,0 +81,0 @@ * @description |
@@ -30,3 +30,3 @@ "use strict"; | ||
* @description | ||
* Creates a virtual dom node that can be later transformed into a real node and updated. | ||
* Creates a virtual node that can be converted into html. | ||
* | ||
@@ -38,7 +38,2 @@ * @param {String} type - The tagname of the element. | ||
function Node (type, attrs, children) { | ||
if (attrs != null && "innerHTML" in attrs) { | ||
children = attrs.innerHTML; | ||
delete attrs.innerHTML; | ||
} | ||
this.type = type; | ||
@@ -53,3 +48,3 @@ this.attrs = attrs; | ||
* @description | ||
* Mark instances as a the nodes. | ||
* Mark instances as VDO nodes. | ||
*/ | ||
@@ -67,3 +62,4 @@ node.isVirtual = true; | ||
var attrs = ""; | ||
var children = this.children; | ||
var children = ""; | ||
var childNodes = this.children; | ||
@@ -77,8 +73,12 @@ // Build attrs string. | ||
if (children === false) { | ||
if (childNodes === false) { | ||
// Self closing nodes will not have children. | ||
return "<" + this.type + attrs + ">"; | ||
} else if (Array.isArray(children)) { | ||
// Cast child nodes to string. | ||
children = children.join(""); | ||
} else if (Array.isArray(childNodes)) { | ||
// Cast all children to strings, escaping non vdo nodes. | ||
for (var child, i = 0, len = childNodes.length; i < len; i++) { | ||
child = childNodes[i]; | ||
if (child == null) continue; | ||
children += child.isVirtual ? child : escape(child); | ||
} | ||
} | ||
@@ -85,0 +85,0 @@ |
{ | ||
"name": "vdo", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Minimal JSX compatible html focused templating engine.", | ||
@@ -5,0 +5,0 @@ "author": "Dylan Piercey <pierceydylan@gmail.com>", |
# VDO | ||
The lightweight JSX compatible templating engine. | ||
Perfect for creating html strings server side or in browser. | ||
Check out [diffhtml](https://github.com/tbranyen/diffhtml) for React style diffing. | ||
# Why | ||
@@ -18,2 +21,3 @@ JSX is powerful compared to other templating engines but it has some warts. | ||
* Optimized for rendering html. | ||
* Escaped values by default. | ||
* JSX compatible. | ||
@@ -28,7 +32,2 @@ | ||
#### Bower | ||
```console | ||
bower install vdo | ||
``` | ||
# Example | ||
@@ -62,2 +61,13 @@ | ||
+ **safe(html)** : Marks html as safe as a VDO child node. | ||
```javascript | ||
// Use safe instead of "innerHTML" when coming from react. | ||
// This allows for mixes of safe and unsafe html in the same node. | ||
const myHTMLStr = "<br/>"; | ||
const vNode = <div>{ vdo.safe(myHTMLStr) }</div>; | ||
Strong(vNode); //-> <div><br/></div> | ||
``` | ||
+ **with(context, renderer)** : Gives all components inside a render function some external `context`. | ||
@@ -64,0 +74,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28424
9
219
108