Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add key-in helper #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ gte | `if (a >= b)` | `{{if (gte a b)}}`
lt | `if (a < b)` | `{{if (lt a b)}}`
lte | `if (a <= b)` | `{{if (lte a b)}}`
is-array | `if (Ember.isArray(a))` | `{{if (is-array a)}}`
key-in | `if (key in a)` | `{{if (key-in 'key' a)}}`

## Install

Expand Down
4 changes: 4 additions & 0 deletions addon/helpers/key-in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

export function keyIn(params) {
return params[0] in params[1];
}
12 changes: 12 additions & 0 deletions app/helpers/key-in.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
export { keyIn } from 'ember-truth-helpers/helpers/key-in';

var forExport = null;

if (Ember.Helper) {
forExport = Ember.Helper.helper(keyIn);
} else if (Ember.HTMLBars.makeBoundHelper) {
forExport = Ember.HTMLBars.makeBoundHelper(keyIn);
}

export default forExport;
2 changes: 2 additions & 0 deletions app/initializers/truth-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { gtHelper } from 'ember-truth-helpers/helpers/gt';
import { gteHelper } from 'ember-truth-helpers/helpers/gte';
import { ltHelper } from 'ember-truth-helpers/helpers/lt';
import { lteHelper } from 'ember-truth-helpers/helpers/lte';
import { keyInHelper } from 'ember-truth-helpers/helpers/key-in';

export function initialize(/* container, application */) {

Expand All @@ -30,6 +31,7 @@ export function initialize(/* container, application */) {
registerHelper('gte', gteHelper);
registerHelper('lt', ltHelper);
registerHelper('lte', lteHelper);
registerHelper('key-in', keyInHelper);
}

export default {
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/helpers/key-in-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Ember from 'ember';
import { moduleForComponent, test } from 'ember-qunit';
import { registerHelper } from 'ember-truth-helpers/utils/register-helper';
import {
keyIn
} from 'ember-truth-helpers/helpers/key-in';

moduleForComponent('key-in', 'helper:key-in', {
integration: true,
beforeEach: function() {
// Do not register helpers from Ember 1.13 onwards, starting from 1.13 they
// will be auto-discovered.
if (!Ember.Helper) {
registerHelper('key-in', keyIn);
}
}
});

test('boolean values', function(assert) {
var fakeContextObject = Ember.Object.create({
valueA: null
});
this.set('contextChild', fakeContextObject);
this.render(
Ember.HTMLBars.compile("[{{key-in 'valueA' contextChild}}] [{{key-in 'valueB' contextChild}}]")
);

assert.equal(this.$().text(), '[true] [false]', 'value should be "[true] [false]"');
});