Skip to content

Commit

Permalink
Merge pull request #16 from beforesemicolon/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ECorreia45 authored Jul 6, 2021
2 parents ddc7b16 + 26a21ee commit 7c0e131
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
4 changes: 3 additions & 1 deletion core/parser/render-by-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const {processCustomAttributeValue} = require("./utils/process-custom-attribute-
const {defaultAttributesName} = require("../default-attributes");

function renderByAttribute(node, options) {
const customAttrs = new Set([...defaultAttributesName, ...Object.keys(options.customAttributes)]);
const customAttrs = Array.from(
new Set([...defaultAttributesName, ...Object.keys(options.customAttributes)])
);

for (let attr of customAttrs) {
if (node.attributes.hasOwnProperty(attr) && options.customAttributes[attr]) {
Expand Down
23 changes: 23 additions & 0 deletions core/parser/render-by-attribute.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const {defaultAttributesMap} = require("../default-attributes");
const {HTMLNode} = require("./HTMLNode");
const {renderByAttribute} = require('./render-by-attribute');

describe('render-by-attribute', () => {
it('should return node if not special attr', () => {
const node = (new HTMLNode('<p>paragraph</p>')).childNodes()[0];

expect(renderByAttribute(node, {
customAttributes: defaultAttributesMap,
data: {}
})).toEqual(node)
});

it('should string if attribute match', () => {
const node = (new HTMLNode('<p #repeat="2">{$item}</p>')).childNodes()[0];

expect(renderByAttribute(node, {
customAttributes: defaultAttributesMap,
data: {}
})).toEqual('<p>1</p><p>2</p>')
});
});
6 changes: 4 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@beforesemicolon/html-plus",
"version": "0.4.3",
"version": "0.4.4",
"description": "HTML Template Engine/Language",
"main": "dist/index.js",
"files": [
Expand Down

0 comments on commit 7c0e131

Please sign in to comment.