Skip to content
This repository was archived by the owner on Aug 2, 2020. It is now read-only.

Commit 89980e2

Browse files
committed
Updated UMD code.
Removed Grunt. Switched to textContext from innerText. Switched to mocha for testing.
1 parent 5d58502 commit 89980e2

File tree

11 files changed

+118
-171
lines changed

11 files changed

+118
-171
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test/

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
language: node_js
22
node_js:
3-
- "0.10"
3+
- "4"
4+
- "5"
5+
- "6"
46
before_install:
5-
- npm install -g grunt-cli
7+
- if [[ `npm -v` != 3* ]]; then npm i -g npm@3; fi
8+
sudo: false

Gruntfile.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
[![](https://api.travis-ci.org/neogeek/de-pre.js.svg)](https://travis-ci.org/neogeek/de-pre.js) [![](https://david-dm.org/neogeek/de-pre.js/dev-status.svg)](https://david-dm.org/neogeek/de-pre.js/#info=devDependencies)
2-
3-
#de-pre.js
1+
# de-pre.js
42

53
> Removes excess indentation from the contents of pre tags, allowing proper indentation in HTML.
64
7-
##Usage
5+
[![](https://api.travis-ci.org/neogeek/de-pre.js.svg)](https://travis-ci.org/neogeek/de-pre.js) [![](https://david-dm.org/neogeek/de-pre.js/dev-status.svg)](https://david-dm.org/neogeek/de-pre.js?type=dev)
6+
7+
## Usage
88

99
```javascript
1010
depre('pre');
@@ -26,7 +26,7 @@ Take for example the following `pre` tag nested inside a `div`:
2626

2727
The contents of the `pre` tag will render like this when viewed in a browser.
2828

29-
```
29+
```json
3030
{
3131
"name": "CanvasToVideo",
3232
"description": "An experiment in converting Canvas animations to video.",
@@ -36,7 +36,7 @@ The contents of the `pre` tag will render like this when viewed in a browser.
3636

3737
With de-pre.js it will render like this:
3838

39-
```
39+
```json
4040
{
4141
"name": "CanvasToVideo",
4242
"description": "An experiment in converting Canvas animations to video.",

de-pre.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,46 @@
22
* de-pre.js
33
* https://github.com/neogeek/de-pre.js
44
*
5-
* Copyright (c) 2014 Scott Doxey
5+
* Copyright (c) 2016 Scott Doxey
66
* Released under the MIT license.
77
*/
88

99
(function (root, factory) {
1010

1111
'use strict';
1212

13-
if (typeof define === 'function' && define.amd !== undefined) {
13+
if (typeof define === 'function' && define.amd) {
1414

1515
define([], factory);
1616

17+
} else if (typeof module === 'object' && module.exports) {
18+
19+
module.exports = factory();
20+
1721
} else {
1822

19-
root.depre = factory;
23+
root.returnExports = factory();
2024

2125
}
2226

23-
}(this, function (tag) {
27+
}(this, function () {
2428

2529
'use strict';
2630

27-
Array.prototype.slice.call(document.querySelectorAll(tag)).forEach(function (obj) {
31+
return function (tag) {
32+
33+
Array.prototype.slice.call(document.querySelectorAll(tag || 'pre')).forEach(function (obj) {
34+
35+
var indent = obj.previousSibling.nodeValue.match(/([ \t]*)$/),
36+
contents = obj.textContent;
2837

29-
var indent = obj.previousSibling.nodeValue.match(/([ \t]*)$/),
30-
contents = obj.innerText;
38+
contents = contents.replace(new RegExp('(^|\n)' + indent[1], 'g'), '$1');
39+
contents = contents.replace(/^\s+|\s+$/g, '');
3140

32-
contents = contents.replace(new RegExp('(^|\n)' + indent[1], 'g'), '$1');
33-
contents = contents.replace(/^\s+|\s+$/g, '');
41+
obj.textContent = contents;
3442

35-
obj.innerText = contents;
43+
});
3644

37-
});
45+
};
3846

3947
}));

package.json

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
{
2-
"name": "de-pre.js",
3-
"description": "Removes excess indentation from the contents of pre tags, allowing proper indentation in HTML.",
4-
"version": "0.0.1",
5-
"main": "de-pre.js",
6-
"devDependencies": {
7-
"grunt": "0.4.5",
8-
"grunt-contrib-watch": "0.6.1",
9-
"grunt-contrib-jasmine": "0.7.0",
10-
"grunt-contrib-uglify": "0.5.1",
11-
"grunt-jslint": "1.1.12",
12-
"grunt-notify": "0.3.1",
13-
"matchdep": "0.3.0"
14-
},
15-
"scripts": {
16-
"test": "grunt test"
17-
}
2+
"name": "de-pre.js",
3+
"description": "Removes excess indentation from the contents of pre tags, allowing proper indentation in HTML.",
4+
"version": "0.0.2",
5+
"main": "de-pre.js",
6+
"devDependencies": {
7+
"jsdom": "9.6.0",
8+
"jsdom-global": "2.1.0",
9+
"jslint": "0.10.3",
10+
"mocha": "3.1.0"
11+
},
12+
"scripts": {
13+
"test": "jslint de-pre.js && mocha test/**/*.js -r jsdom-global/register"
14+
},
15+
"private": true
1816
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

test/specs/test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const fs = require('fs');
2+
3+
const assert = require('assert');
4+
5+
const depre = require('../../de-pre.js');
6+
7+
describe('de-pre.js', function () {
8+
9+
it('Testing removal of spaces.', function (done) {
10+
11+
fs.readFile('test/fixtures/a-spaces.html', 'utf8', function (err, data) {
12+
13+
document.body.innerHTML = data;
14+
15+
depre('pre');
16+
17+
assert.equal(document.querySelector('pre').textContent.match(/\s*\{/)[0], '{');
18+
19+
done();
20+
21+
});
22+
23+
});
24+
25+
it('Testing removal of spaces without specifying tag.', function (done) {
26+
27+
fs.readFile('test/fixtures/a-spaces.html', 'utf8', function (err, data) {
28+
29+
document.body.innerHTML = data;
30+
31+
depre();
32+
33+
assert.equal(document.querySelector('pre').textContent.match(/\s*\{/)[0], '{');
34+
35+
done();
36+
37+
});
38+
39+
});
40+
41+
it('Testing removal of tabs.', function (done) {
42+
43+
fs.readFile('test/fixtures/a-tabs.html', 'utf8', function (err, data) {
44+
45+
document.body.innerHTML = data;
46+
47+
depre('pre');
48+
49+
assert.equal(document.querySelector('pre').textContent.match(/\s*\{/)[0], '{');
50+
51+
done();
52+
53+
});
54+
55+
});
56+
57+
it('Testing removal of mixed whitespace.', function (done) {
58+
59+
fs.readFile('test/fixtures/a-mixed.html', 'utf8', function (err, data) {
60+
61+
document.body.innerHTML = data;
62+
63+
depre('pre');
64+
65+
assert.equal(document.querySelector('pre').textContent.match(/\s*\{/)[0], '{');
66+
67+
done();
68+
69+
});
70+
71+
});
72+
73+
});

0 commit comments

Comments
 (0)