Skip to content

Commit

Permalink
Auto merge of #93 - vikram7:vr-add-classify, r=poteto
Browse files Browse the repository at this point in the history
Add classify helper

The PR adds a `classify` helper per issue https://github.com/DockYard/ember-composable-helpers/issues/67
  • Loading branch information
homu committed Feb 26, 2016
2 parents bcab075 + fe655d2 commit 87d17d0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ For action helpers, this will mean better currying semantics:
* [String](#string-helpers)
+ [`camelize`](#camelize)
+ [`capitalize`](#capitalize)
+ [`classify`](#classify)
+ [`dasherize`](#dasherize)
+ [`underscore`](#underscore)
+ [`w`](#w)
Expand Down Expand Up @@ -150,6 +151,16 @@ Capitalizes a string using `Ember.String.capitalize`.
**[⬆️ back to top](#available-helpers)**
#### `classify`
Classifies a string using `Ember.String.classify`.
```hbs
{{classify "hello jim bob"}}
{{classify stringWithDashes}}
```
**[⬆️ back to top](#available-helpers)**
#### `dasherize`
Capitalizes a string using `Ember.String.dasherize`.
Expand Down
12 changes: 12 additions & 0 deletions addon/helpers/classify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
const {
Helper: { helper },
String: { classify: _classify }
} = Ember;

export function classify([string]) {
string = string || '';
return _classify(string);
}

export default helper(classify);
1 change: 1 addition & 0 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { default as AppendHelper } from './helpers/append';
export { default as CamelizeHelper } from './helpers/camelize';
export { default as CapitalizeHelper } from './helpers/capitalize';
export { default as ClassifyHelper } from './helpers/classify';
export { default as CompactHelper } from './helpers/compact';
export { default as ComputeHelper } from './helpers/compute';
export { default as ContainsHelper } from './helpers/contains';
Expand Down
1 change: 1 addition & 0 deletions app/helpers/classify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default, classify } from 'ember-composable-helpers/helpers/classify';
46 changes: 46 additions & 0 deletions tests/integration/helpers/classify-test.js
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('classify', 'Integration | Helper | {{classify}}', {
integration: true
});

test('It converts camelCase correctly', function(assert) {
this.render(hbs`{{classify "andAnother"}}`);

let expected = 'AndAnother';

assert.equal(this.$().text().trim(), expected, 'classifies camelCased strings');
});

test('It converts underscored strings correctly', function(assert) {
this.render(hbs`{{classify "harry_potter"}}`);

let expected = 'HarryPotter';

assert.equal(this.$().text().trim(), expected, 'classifies underscored strings');
});

test('It converts spaces in strings correctly', function(assert) {
this.render(hbs`{{classify "age is foolish and forgetful when it underestimates youth"}}`);

let expected = 'AgeIsFoolishAndForgetfulWhenItUnderestimatesYouth';

assert.equal(this.$().text().trim(), expected, 'classifies strings with spaces');
});

test('It correctly handles empty string input', function(assert) {
this.render(hbs`{{classify ""}}`);

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`{{classify undefined}}`);

let expected = '';

assert.equal(this.$().text().trim(), expected, 'renders empty string if undefined input');
});

0 comments on commit 87d17d0

Please sign in to comment.