Skip to content

Commit

Permalink
Committed by npm script.
Browse files Browse the repository at this point in the history
  • Loading branch information
nashwaan committed May 25, 2017
1 parent 7ec0751 commit d9f2848
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/js2xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ function writeInstruction(instruction, options) {
break;
}
}
return '<?' + key + (instruction[key] ? ' ' + instruction[key] : '') + '?>';
if (typeof instruction[key] === 'object') {
return '<?' + key + writeAttributes(instruction[key][options.attributesKey], options) + '?>';
} else {
return '<?' + key + (instruction[key] ? ' ' + instruction[key] : '') + '?>';
}
}

function writeComment(comment, options) {
Expand Down Expand Up @@ -143,7 +147,7 @@ function writeElements(elements, options, depth, firstLine) {
case 'text': return xml + (options.indentText ? indent : '') + writeText(element[options.textKey], options);
case 'instruction':
var instruction = {};
instruction[element[options.nameKey]] = element[options.instructionKey];
instruction[element[options.nameKey]] = element[options.attributesKey] ? element : element[options.instructionKey];
return xml + (options.indentInstruction ? indent : '') + writeInstruction(instruction, options);
}
}, '');
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xml-js",
"version": "1.3.1",
"version": "1.3.2",
"description": "A convertor between XML text and Javascript object / JSON text.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -58,7 +58,7 @@
"start": "npm-run-all --parallel bundle:jasmine watch:istanbul live:* open:*",
"git:commit": "git add . && git commit -a -m \"Committed by npm script.\" && git push origin master",
"git:push": "git push origin master",
"deploy": "npm-run-all --serial coverage git:commit",
"deploy": "npm-run-all --serial coverage git:*",
"coverage": "npm-run-all coverage:*",
"coverage:a-step": "npm run istanbul",
"coverage:coveralls": "cat ./test/browse-coverage/lcov.info | coveralls",
Expand Down
16 changes: 16 additions & 0 deletions test/js2xml_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,22 @@ describe('Testing js2xml.js:', function () {

});

describe('Various options:', function () {

describe('options = {instructionHasAttributes: true}', function () {

it('Write processing instruction attributes, {compact: true}', function () {
expect(convert.js2xml({"_instruction":{"go":{"_attributes":{"to":"there"}}}}, {compact: true})).toEqual('<?go to="there"?>');
});

it('Write processing instruction attributes, {compact: false}', function () {
expect(convert.js2xml({"elements":[{"type":"instruction","name":"go","attributes":{"to":"there"}}]})).toEqual('<?go to="there"?>');
});

});

});

describe('User reported issues:', function () {

describe('case by Jan T. Sott', function () {
Expand Down

0 comments on commit d9f2848

Please sign in to comment.