Add stringify view for objects
This commit is contained in:
parent
e36815347b
commit
c49f0099d9
5 changed files with 47 additions and 1 deletions
5
app/helpers/stringify.js
Normal file
5
app/helpers/stringify.js
Normal 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
5
app/helpers/type-of.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { helper } from '@ember/component/helper';
|
||||
|
||||
export default helper(function typeOf([value]) {
|
||||
return typeof value;
|
||||
});
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
17
tests/integration/helpers/stringify-test.js
Normal file
17
tests/integration/helpers/stringify-test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
17
tests/integration/helpers/type-of-test.js
Normal file
17
tests/integration/helpers/type-of-test.js
Normal 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');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue