Comparing version 1.0.1 to 1.1.0
@@ -7,2 +7,6 @@ # hstream change log | ||
## 1.1.0 | ||
* Add `_replaceHtml` option that replaces the outer html of an element | ||
## 1.0.1 | ||
@@ -9,0 +13,0 @@ |
27
index.js
@@ -115,4 +115,4 @@ var HTMLParser = require('htmlparser2').Parser | ||
var el = { tagName: name, attrs: attrs } | ||
stack.push(el) | ||
selfClosingIndex = parser.startIndex | ||
stack.push(el) | ||
@@ -122,2 +122,12 @@ var match = matches() | ||
if (match) { | ||
// store the update object so we can use it in the close tag handler | ||
el.update = match.update | ||
// replacing the entire element; don't push the open tag | ||
if (match.update._replaceHtml) { | ||
replacing = true | ||
el.replaceOuter = true | ||
return | ||
} | ||
if (hasAttrs(match.update)) { | ||
@@ -134,9 +144,5 @@ addAttrs(tag, attrs, match.update).forEach(queue) | ||
if (match.update._html) { | ||
queue(match.update._html) | ||
replacing = true | ||
el.replaceContents = true | ||
} | ||
// store the update object so we can use it in the close tag handler | ||
el.update = match.update | ||
} else { | ||
@@ -159,3 +165,12 @@ queue(tag) | ||
var el = stack.pop() | ||
if (el.replaceContents) replacing = false // stop replacing | ||
// replaced the entire element; don't push the closing tag | ||
if (el.replaceOuter) { | ||
replacing = false | ||
queue(el.update._replaceHtml) | ||
return | ||
} | ||
if (el.replaceContents) { | ||
replacing = false // stop replacing | ||
queue(el.update._html) | ||
} | ||
@@ -162,0 +177,0 @@ if (selfClosingIndex === parser.startIndex) return |
{ | ||
"name": "hstream", | ||
"description": "streaming html templates", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"author": "Renée Kooi <renee@kooi.me>", | ||
"bugs": { | ||
"url": "https://github.com/goto-bus-stop/hstream/issues" | ||
"url": "https://github.com/stackhtml/hstream/issues" | ||
}, | ||
"dependencies": { | ||
"css-what": "^2.1.0", | ||
"dedent": "^0.7.0", | ||
"htmlparser2": "^3.9.2", | ||
@@ -16,2 +15,3 @@ "through2": "^2.0.3" | ||
"devDependencies": { | ||
"dedent": "^0.7.0", | ||
"hyperstream": "^1.2.2", | ||
@@ -24,3 +24,3 @@ "nanobench": "^2.1.0", | ||
}, | ||
"homepage": "https://github.com/goto-bus-stop/hstream", | ||
"homepage": "https://github.com/stackhtml/hstream", | ||
"keywords": [ | ||
@@ -35,3 +35,3 @@ "html", | ||
"type": "git", | ||
"url": "https://github.com/goto-bus-stop/hstream.git" | ||
"url": "https://github.com/stackhtml/hstream.git" | ||
}, | ||
@@ -38,0 +38,0 @@ "scripts": { |
@@ -18,4 +18,4 @@ # hstream | ||
[npm-url]: https://www.npmjs.com/package/hstream | ||
[travis-image]: https://img.shields.io/travis/goto-bus-stop/hstream.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/goto-bus-stop/hstream | ||
[travis-image]: https://img.shields.io/travis/stackhtml/hstream.svg?style=flat-square | ||
[travis-url]: https://travis-ci.org/stackhtml/hstream | ||
[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square | ||
@@ -60,2 +60,3 @@ [standard-url]: http://npm.im/standard | ||
- `_appendHtml` - Append some HTML to the matching element | ||
- `_replaceHtml` - Replace the entire element with some HTML | ||
@@ -62,0 +63,0 @@ All properties accept streams and strings. |
@@ -5,3 +5,3 @@ var test = require('tape') | ||
test('replace html with a string', function (t) { | ||
test('replace contents with a string', function (t) { | ||
var hs = hyperstream({ | ||
@@ -18,3 +18,3 @@ '#a': { _html: 'it worked' } | ||
test('replace html with a bare string', function (t) { | ||
test('replace contents with a bare string', function (t) { | ||
var hs = hyperstream({ | ||
@@ -31,3 +31,3 @@ '#a': 'it worked' | ||
test('replace html with a stream', function (t) { | ||
test('replace contents with a stream', function (t) { | ||
var hs = hyperstream({ | ||
@@ -79,1 +79,13 @@ '#a': { _html: 'it worked' } | ||
}) | ||
test('replace element', function (t) { | ||
var hs = hyperstream({ | ||
'#slot': { _replaceHtml: '<div id="xyz">new element</div>' } | ||
}) | ||
concat(hs, function (err, result) { | ||
t.ifError(err) | ||
t.equal(result + '', '<div id="a"><div id="xyz">new element</div></div>') | ||
t.end() | ||
}) | ||
hs.end('<div id="a"><x id="slot">template slot</x></div>') | ||
}) |
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
602644
3
512
109
7
- Removeddedent@^0.7.0
- Removeddedent@0.7.0(transitive)