Skip to content

Commit

Permalink
Add classify helper
Browse files Browse the repository at this point in the history
  • Loading branch information
vikram7 committed Feb 26, 2016
1 parent bcab075 commit fe655d2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
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
@@ -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
@@ -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
@@ -0,0 +1 @@
export { default, classify } from 'ember-composable-helpers/helpers/classify';
46 changes: 46 additions & 0 deletions tests/integration/helpers/classify-test.js
@@ -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 fe655d2

Please sign in to comment.