-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from base-cms/clean-elements
Add unit tests and update pennwell default rule
- Loading branch information
Showing
19 changed files
with
1,579 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
docker-compose run \ | ||
--rm \ | ||
yarn \ | ||
run coverage $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
docker-compose run \ | ||
--rm \ | ||
yarn \ | ||
run test $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { isArray } = Array; | ||
|
||
module.exports = ($, attributes) => { | ||
const attrs = isArray(attributes) ? attributes : []; | ||
attrs.forEach((attr) => { | ||
$(`[${attr}]`).each(function () { | ||
$(this).removeAttr(attr); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = ($) => { | ||
$('*').each(function () { | ||
const { attribs } = $(this)[0]; | ||
Object.keys(attribs).forEach((attr) => { | ||
if (/^data-/i.test(attr)) { | ||
$(this).removeAttr(attr); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module.exports = ($, selector) => { | ||
$(selector).each(function () { | ||
$(this).replaceWith(''); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const cheerio = require('cheerio'); | ||
|
||
const cleanElementText = ($, $el) => { | ||
const contents = $el.contents()[0]; | ||
|
||
if (contents && contents.type === 'text') { | ||
const { data = '' } = contents; | ||
const cleaned = data.replace(/\s\s+/g, ' ').trim(); | ||
contents.data = cleaned; | ||
} | ||
if ($el.children().length) { | ||
$el.children().each(function () { | ||
cleanElementText($, $(this)); | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = (html) => { | ||
const str = (html || '') | ||
.replace(/[\r\n\f\v\t\b\\]/g, ' ') | ||
.trim() | ||
.replace(/>\s+</g, '><') | ||
.replace(/\s+%{\[/g, '%{[') | ||
.replace(/\]}%\s+/g, ']}%'); | ||
const $ = cheerio.load(str, { decodeEntities: false }); | ||
cleanElementText($, $('body')); | ||
return $('body').html(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
globals: { | ||
describe: 'readonly', | ||
it: 'readonly', | ||
expect: 'readonly', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const chai = require('chai'); | ||
const request = require('supertest'); | ||
const sinon = require('sinon'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
|
||
global.chai = chai; | ||
global.request = request; | ||
global.sinon = sinon; | ||
global.chai = chai; | ||
global.expect = chai.expect; | ||
|
||
chai.use(chaiAsPromised); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--recursive | ||
--async-only | ||
--timeout 2000 | ||
--require ./test/bootstrap.js |
Oops, something went wrong.