Browse Source

Update toHTML opts

pull/4103/head
Artur Arseniev 4 years ago
parent
commit
03a0c84068
  1. 7
      src/dom_components/model/Component.js
  2. 2
      test/specs/dom_components/model/Component.js

7
src/dom_components/model/Component.js

@ -1371,10 +1371,9 @@ export default class Component extends Model.extend(Styleable) {
* Return HTML string of the component
* @param {Object} [opts={}] Options
* @param {String} [opts.tag] Custom tagName
* @param {Object|Function} [opts.attributes=null] You can pass an object of custom attributes to replace.
* @param {Object|Function} [opts.attributes=null] You can pass an object of custom attributes to replace with the current ones or you can even pass a function to generate attributes dynamically.
* @param {Boolean} [opts.withProps] Include component properties as `data-gjs-*` attributes. This allows you to have re-importable HTML.
* @param {Boolean} [opts.beautifyAttr] In case the attribute value contains a `"` char, instead of escaping it (`attr="value ""`), the attribute will be quoted using single quotes (`attr='value "'`).
* with the current one or you can even pass a function to generate attributes dynamically
* @param {Boolean} [opts.altQuoteAttr] In case the attribute value contains a `"` char, instead of escaping it (`attr="value ""`), the attribute will be quoted using single quotes (`attr='value "'`).
* @return {String} HTML string
* @example
* // Simple HTML return
@ -1436,7 +1435,7 @@ export default class Component extends Model.extend(Styleable) {
val && attrs.push(attr);
} else {
let valueRes = '';
if (opts.beautifyAttr && isString(val) && val.indexOf('"') >= 0) {
if (opts.altQuoteAttr && isString(val) && val.indexOf('"') >= 0) {
valueRes = `'${val.replace(/'/g, ''')}'`;
} else {
const value = isString(val) ? val.replace(/"/g, '"') : val;

2
test/specs/dom_components/model/Component.js

@ -167,7 +167,7 @@ describe('Component', () => {
resArr = '[1,"string",true]';
resObj = '{"a":1,"b":"string","c":true}';
res = `<div data-gjs-bool data-gjs-string='${resStr}' data-gjs-array='${resArr}' data-gjs-object='${resObj}' data-gjs-empty="" data-gjs-zero="0"></div>`;
expect(obj.toHTML({ withProps: true, beautifyAttr: true })).toEqual(res);
expect(obj.toHTML({ withProps: true, altQuoteAttr: true })).toEqual(res);
});
test('Manage correctly boolean attributes', () => {

Loading…
Cancel
Save