Skip to content

Commit

Permalink
create multiple elements (quite ugly so far)
Browse files Browse the repository at this point in the history
Rate limit · GitHub

Whoa there!

You have triggered an abuse detection mechanism.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

bredele committed Jul 13, 2016
1 parent 3023153 commit ac50852
Showing 2 changed files with 14 additions and 4 deletions.
11 changes: 7 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -14,34 +14,37 @@ module.exports = function(arr, ...args) {
var match
var node
var chars
var parent = document.createDocumentFragment()
while(str) {
chars = true
if(str.indexOf('</') == 0) {
match = str.match(end)
if(match) {
str = str.substring(match[0].length)
match[0].replace(end, () => {
})
var tmp = node.parentElement
if(tmp) parent = tmp
chars = false;
}
} else if(str.indexOf('<') == 0 ) {
match = str.match(start)
if(match) {
str = str.substring(match[0].length)
node = document.createElement(match[1])
parent.appendChild(node)
parent = node
chars = false
}
}
if(chars) {
var index = str.indexOf('<')
var text = index < 0 ? str : str.substring(0, index)
str = index < 0 ? '' : str.substring(index)
node.appendChild(document.createTextNode(text))
parent.appendChild(document.createTextNode(text))
}

if(!str && ++i != length) {
str = args[i - 1] + arr[i]
}
}
return node
return parent
}
7 changes: 7 additions & 0 deletions test/vomit.js
Original file line number Diff line number Diff line change
@@ -17,3 +17,10 @@ tape('should interpolate string', (test) => {
var btn = vomit`<button>${label}</button>`
test.equal(btn.outerHTML, '<button>hello</button>')
})

tape('should create multiple elements', (test) => {
test.plan(1)
var label = 'hello'
var section = vomit`<section><button>${label}</button></section>`
test.equal(section.outerHTML, '<section><button>hello</button></section>')
})

0 comments on commit ac50852

Please sign in to comment.