Skip to content

Commit 17f931d

Browse files
author
E.Azer Koçulu
committed
initial commit
0 parents  commit 17f931d

File tree

6 files changed

+72
-0
lines changed

6 files changed

+72
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
npm-debug.log

.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test
2+
test.js
3+
example
4+
examples

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## new-element
2+
3+
Create DOM elements from HTML string
4+
5+
```js
6+
newElement('<input />')
7+
newElement('<a href="{link}">{text}</a>', { link: 'foo.com', text: 'click' })
8+
```
9+
10+
## Install
11+
12+
```bash
13+
$ npm install new-element
14+
```

index.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var domify = require("domify");
2+
var format = require("new-format");
3+
4+
module.exports = newElement;
5+
6+
function newElement (html, vars) {
7+
if (arguments.length == 1) return domify(html);
8+
9+
return domify(format(html, vars));
10+
}

package.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "new-element",
3+
"version": "0.0.0",
4+
"description": "Create a new DOM element from string",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "fox"
8+
},
9+
"devDependencies": {
10+
"fox": "*"
11+
},
12+
"keywords": [
13+
"dom"
14+
],
15+
"repository": {
16+
"url": "[email protected]:azer/new-element.git",
17+
"type": "git"
18+
},
19+
"author": "Azer Koçulu <[email protected]>",
20+
"license": "BSD",
21+
"dependencies": {
22+
"new-format": "0.0.1",
23+
"domify": "~1.0.0"
24+
}
25+
}

test.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var newElement = require("./");
2+
3+
beforeEach(function(){
4+
document.body.innerHTML = '';
5+
});
6+
7+
it('creates an element', function(){
8+
var el = newElement('<input value="whatsup" />');
9+
expect(el.tagName).to.equal('INPUT');
10+
expect(el.value).to.equal('whatsup');
11+
});
12+
13+
it('supports formatting', function(){
14+
var el = newElement('<input value="{val}" class="{cls}" />', { val: 'foo', cls: 'bar' });
15+
expect(el.value).to.equal('foo');
16+
expect(el.className).to.equal('bar');
17+
});

0 commit comments

Comments
 (0)