-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #87 - vikram7:vr-add-underscore, r=poteto
Add string underscore helper This PR adds the `underscore` helper per issue https://github.com/DockYard/ember-composable-helpers/issues/69
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Ember from 'ember'; | ||
const { | ||
Helper: { helper }, | ||
String: { underscore: _underscore } | ||
} = Ember; | ||
|
||
export function underscore([string]) { | ||
string = string || ''; | ||
return _underscore(string); | ||
} | ||
|
||
export default helper(underscore); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default, underscore } from 'ember-composable-helpers/helpers/underscore'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { moduleForComponent, test } from 'ember-qunit'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
|
||
moduleForComponent('underscore', 'Integration | Helper | {{underscore}}', { | ||
integration: true | ||
}); | ||
|
||
test('It converts camelCase correctly', function(assert) { | ||
this.render(hbs`{{underscore "andAnother"}}`); | ||
|
||
let expected = 'and_another'; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'converts camelCase to underscored'); | ||
}); | ||
|
||
test('It converts dashes to underscores', function(assert) { | ||
this.render(hbs`{{underscore "harry-potter"}}`); | ||
|
||
let expected = 'harry_potter'; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'converts dashes to underscores'); | ||
}); | ||
|
||
test('It converts spaces to underscores', function(assert) { | ||
this.render(hbs`{{underscore "age is foolish and forgetful when it underestimates youth"}}`); | ||
|
||
let expected = 'age_is_foolish_and_forgetful_when_it_underestimates_youth'; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'converts spaces to underscores'); | ||
}); | ||
|
||
test('It correctly handles empty string input', function(assert) { | ||
this.render(hbs`{{underscore ""}}`); | ||
|
||
let expected = ''; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'renders empty string if input is empty string'); | ||
}); | ||
|
||
test('It correctly handles undefined input', function(assert) { | ||
this.render(hbs`{{underscore undefined}}`); | ||
|
||
let expected = ''; | ||
|
||
assert.equal(this.$().text().trim(), expected, 'renders empty string if undefined input'); | ||
}); |