Add stringify view for objects

This commit is contained in:
Stanislav Romanov 2022-03-25 15:10:34 +03:00
parent e36815347b
commit c49f0099d9
5 changed files with 47 additions and 1 deletions

5
app/helpers/stringify.js Normal file
View file

@ -0,0 +1,5 @@
import { helper } from '@ember/component/helper';
export default helper(function stringify([value] /*, named*/) {
return JSON.stringify(value, null, 1);
});

5
app/helpers/type-of.js Normal file
View file

@ -0,0 +1,5 @@
import { helper } from '@ember/component/helper';
export default helper(function typeOf([value]) {
return typeof value;
});

View file

@ -25,7 +25,9 @@
{{#each-in item as |key value|}}
<div class="grid grid-cols-3 gap-4 p-4 odd:bg-gray-50">
<div>{{key}}</div>
<div class="col-span-2">{{value}}</div>
<div class="col-span-2">
{{if (eq (type-of value) "object") (stringify value) value}}
</div>
</div>
{{/each-in}}
</div>

View file

@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Helper | stringify', function (hooks) {
setupRenderingTest(hooks);
// TODO: Replace this with your real tests.
test('it renders', async function (assert) {
this.set('inputValue', '1234');
await render(hbs`{{stringify this.inputValue}}`);
assert.dom(this.element).hasText('1234');
});
});

View file

@ -0,0 +1,17 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Helper | type-of', function (hooks) {
setupRenderingTest(hooks);
// TODO: Replace this with your real tests.
test('it renders', async function (assert) {
this.set('inputValue', '1234');
await render(hbs`{{type-of this.inputValue}}`);
assert.dom(this.element).hasText('1234');
});
});