Skip to content

Commit

Permalink
Use extracted dom-utils module
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraq committed Apr 28, 2019
1 parent e81f5d3 commit fc2c9b0
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 30 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"@ultraq/array-utils": "^1.1.0",
"@ultraq/dom-utils": "^0.1.1",
"@ultraq/string-utils": "^1.1.0",
"dumb-query-selector": "^3.3.0",
"jsdom": "~9.12.0"
Expand Down
3 changes: 2 additions & 1 deletion source/standard/processors/IfAttributeProcessor.js
Expand Up @@ -16,7 +16,8 @@

import ExpressionProcessor from '../expressions/ExpressionProcessor.js';
import AttributeProcessor from '../../processors/AttributeProcessor.js';
import {clearChildren} from '../../utilities/Dom.js';

import {clearChildren} from '@ultraq/dom-utils';

/**
* JS equivalent of Thymeleaf's `th:if` attribute processor, includes or
Expand Down
16 changes: 9 additions & 7 deletions source/standard/processors/InsertAttributeProcessor.js
Expand Up @@ -14,13 +14,15 @@
* limitations under the License.
*/

import FragmentAttributeProcessor from './FragmentAttributeProcessor.js';
import StandardDialect from '../StandardDialect.js';
import ExpressionProcessor from '../expressions/ExpressionProcessor.js';
import FragmentSignatureGrammar from '../expressions/FragmentSignatureGrammar.js';
import AttributeProcessor from '../../processors/AttributeProcessor.js';
import {clearChildren, getThymeleafAttributeValue} from '../../utilities/Dom.js';
import {extractFragment} from '../../utilities/Fragments.js';
import FragmentAttributeProcessor from './FragmentAttributeProcessor.js';
import StandardDialect from '../StandardDialect.js';
import ExpressionProcessor from '../expressions/ExpressionProcessor.js';
import FragmentSignatureGrammar from '../expressions/FragmentSignatureGrammar.js';
import AttributeProcessor from '../../processors/AttributeProcessor.js';
import {getThymeleafAttributeValue} from '../../utilities/Dom.js';
import {extractFragment} from '../../utilities/Fragments.js';

import {clearChildren} from '@ultraq/dom-utils';

/**
* JS equivalent of Thymeleaf's `th:insert` attribute processor, inserts the
Expand Down
16 changes: 9 additions & 7 deletions source/standard/processors/ReplaceAttributeProcessor.js
Expand Up @@ -14,13 +14,15 @@
* limitations under the License.
*/

import FragmentAttributeProcessor from './FragmentAttributeProcessor.js';
import StandardDialect from '../StandardDialect.js';
import ExpressionProcessor from '../expressions/ExpressionProcessor.js';
import FragmentSignatureGrammar from '../expressions/FragmentSignatureGrammar.js';
import AttributeProcessor from '../../processors/AttributeProcessor.js';
import {clearChildren, getThymeleafAttributeValue} from '../../utilities/Dom.js';
import {extractFragment} from '../../utilities/Fragments.js';
import FragmentAttributeProcessor from './FragmentAttributeProcessor.js';
import StandardDialect from '../StandardDialect.js';
import ExpressionProcessor from '../expressions/ExpressionProcessor.js';
import FragmentSignatureGrammar from '../expressions/FragmentSignatureGrammar.js';
import AttributeProcessor from '../../processors/AttributeProcessor.js';
import {getThymeleafAttributeValue} from '../../utilities/Dom.js';
import {extractFragment} from '../../utilities/Fragments.js';

import {clearChildren} from '@ultraq/dom-utils';

/**
* JS equivalent of Thymeleaf's `th:relace` attribute processor, replaces the
Expand Down
3 changes: 2 additions & 1 deletion source/standard/processors/UnlessAttributeProcessor.js
Expand Up @@ -16,7 +16,8 @@

import ExpressionProcessor from '../expressions/ExpressionProcessor.js';
import AttributeProcessor from '../../processors/AttributeProcessor.js';
import {clearChildren} from '../../utilities/Dom.js';

import {clearChildren} from '@ultraq/dom-utils';

/**
* JS equivalent of Thymeleaf's `th:unless` attribute processor, excludes or
Expand Down
15 changes: 2 additions & 13 deletions source/utilities/Dom.js
Expand Up @@ -16,17 +16,6 @@

/* global ENVIRONMENT */

/**
* Removes all of an element's child nodes.
*
* @param {Element} element
*/
export function clearChildren(element) {
while (element.firstChild) {
element.removeChild(element.firstChild);
}
}

/**
* Sets a Thymeleaf attribute and value on an existing element. Used primarily
* in tests.
Expand Down Expand Up @@ -65,7 +54,7 @@ export function getThymeleafAttributeValue(element, prefix, processorName) {
export function deserialize(htmlString) {
return ENVIRONMENT === 'browser' ?
/* istanbul ignore next */
document.createRange().createContextualFragment(htmlString) :
require('@ultraq/dom-utils').deserialize(htmlString) :
require('jsdom').jsdom(htmlString, {
features: {
FetchExternalResources: false,
Expand All @@ -84,6 +73,6 @@ export function deserialize(htmlString) {
export function serialize(documentFragment) {
return ENVIRONMENT === 'browser' ?
/* istanbul ignore next */
new XMLSerializer().serializeToString(documentFragment) :
require('@ultraq/dom-utils').serialize(documentFragment) :
require('jsdom').serializeDocument(documentFragment);
}

0 comments on commit fc2c9b0

Please sign in to comment.