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

Upgrade to Ember CLI 0.2.3 #107

Merged
merged 11 commits into from
Apr 17, 2015
Merged
Show file tree
Hide file tree
Changes from 10 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
11 changes: 6 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
indent_size = 4

[*.js]
indent_style = space
indent_size = 2
indent_size = 4

[*.hbs]
insert_final_newline = false
indent_style = space
indent_size = 2
indent_size = 4

[*.css]
indent_style = space
indent_size = 2
indent_size = 4

[*.html]
indent_style = space
indent_size = 2
indent_size = 4

[*.{diff,md}]
trim_trailing_whitespace = false
Empty file modified .ember-cli
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bower_components/
tests/
tmp/

.bowerrc
.editorconfig
Expand Down
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
language: node_js
node_js:
- "0.12"

sudo: false

Expand Down
Empty file modified CHANGELOG.md
100755 → 100644
Empty file.
Empty file modified CLA-CORPORATE.md
100755 → 100644
Empty file.
Empty file modified CLA-INDIVIDUAL.md
100755 → 100644
Empty file.
Empty file modified CONTRIBUTING.md
100755 → 100644
Empty file.
Empty file modified LICENSE.md
100755 → 100644
Empty file.
16 changes: 2 additions & 14 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[![Latest Release](https://img.shields.io/github/release/softlayer/sl-ember-translate.svg)](https://github.com/softlayer/sl-ember-translate/releases) ![Ember CLI version](https://img.shields.io/badge/ember%20cli-0.1.15-orange.svg) [![License](https://img.shields.io/npm/l/sl-ember-translate.svg)](LICENSE.md) [![Downloads](https://img.shields.io/npm/dm/sl-ember-translate.svg)](https://www.npmjs.com/package/sl-ember-translate)
[![Latest Release](https://img.shields.io/github/release/softlayer/sl-ember-translate.svg)](https://github.com/softlayer/sl-ember-translate/releases) ![Ember CLI version](https://img.shields.io/badge/ember%20cli-0.2.3-orange.svg) [![License](https://img.shields.io/npm/l/sl-ember-translate.svg)](LICENSE.md) [![Downloads](https://img.shields.io/npm/dm/sl-ember-translate.svg)](https://www.npmjs.com/package/sl-ember-translate)

[![Dependencies](https://img.shields.io/david/softlayer/sl-ember-translate.svg)](https://david-dm.org/softlayer/sl-ember-translate) [![Dev Dependencies](https://img.shields.io/david/dev/softlayer/sl-ember-translate.svg)](https://david-dm.org/softlayer/sl-ember-translate#info=devDependencies)

Expand Down Expand Up @@ -57,7 +57,7 @@ For more information on using ember-cli, visit [http://www.ember-cli.com/](http:
## Install this addon as a Node module

```
ember install:addon sl-ember-translate
ember install sl-ember-translate
```


Expand Down Expand Up @@ -107,18 +107,6 @@ where each "$x" parameter numerically corresponds to the tokens in the translati

---

### Binding

If you need to pass parameters whose values are bound to other values rather than be hard-coded, use the following format:

```handlebars
{{sl-translate key="ACCESSLOG_LIST_PAGINATION" $0Binding="examplePropertyBoundTo1" $1Binding="examplePropertyBoundTo2" $2Binding="examplePropertyBoundTo3"}}
```

The order of the parameters does not matter.

---

### Used alongside other properties or attribute bindings

You can still use the *sl-translate* component alongside other properties or attribute bindings as well:
Expand Down
Empty file modified RELEASE-INSTRUCTIONS.md
100755 → 100644
Empty file.
64 changes: 31 additions & 33 deletions addon/components/sl-translate.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default Ember.Component.extend({
/**
* Filtered array of parameters passed to this component
*
* Only contains those that are a number that begin with "$" and are to be bound to
* Only contains those that are a number that begin with "$" and are to be
* bound to
*
* @property {Ember.Array} observedParameters
* @default null
Expand All @@ -51,7 +52,8 @@ export default Ember.Component.extend({
/**
* Filtered array of parameters passed to this component
*
* Only contains those that are a number that begin with "$" and also do not end in "Binding"
* Only contains those that are a number that begin with "$" and also do not
* end in "Binding"
*
* @property {Ember.Array} parameters
* @default null
Expand All @@ -76,51 +78,49 @@ export default Ember.Component.extend({
* @observes "init" event
* @returns {void}
*/
extractParameterKeys: function() {
extractParameterKeys: Ember.on( 'init', function() {
var parameters = [],
observedParameters = [],
self = this;
observedParameters = [];

Ember.keys( this ).map( function( key ) {
Ember.keys( this ).map( key => {

// Is a number that begins with $ but doesn't also end with "Binding"
if ( /^\$/.test( key ) && !/^\$.*(Binding)$/.test( key ) ) {
parameters.push( key );
}

// Is a number that begins with $ and was passed as a binding
if ( /^\$[0-9]*$/.test( key ) && self.hasOwnProperty( key + 'Binding' ) ) {
if ( /^\$[0-9]*$/.test( key ) && this.hasOwnProperty( key + 'Binding' ) ) {
observedParameters.push( key );
}
});

this.setProperties({
'parameters' : parameters,
'observedParameters' : observedParameters
observedParameters,
parameters
});
}.on( 'init' ),
}),

/**
* Register observers on filtered parameter list
*
* The reason observers have to be manually (de)registered rather than calling .property() on translateString() is
* because in order to support token replacement within a tranlsation string a user needs to be able to pass in a
* variable amount of (potentially) bound properties. There is not a way to specify such a dynamic list of
* properties in a .property() call.
* The reason observers have to be manually (de)registered rather than
* calling .property() on translateString() is because in order to support
* token replacement within a tranlsation string a user needs to be able to
* pass in a variable amount of (potentially) bound properties. There is not
* a way to specify such a dynamic list of properties in a .property() call.
*
* @function registerObservers
* @observes "willInsertElement" event
* @returns {void}
*/
registerObservers: function() {
var self = this;

this.get( 'observedParameters' ).map( function( key ) {
self.addObserver( key, self, self.setTranslatedString );
registerObservers: Ember.on( 'willInsertElement', function() {
this.get( 'observedParameters' ).map( key => {
this.addObserver( key, this, this.setTranslatedString );
});

this.setTranslatedString();
}.on( 'willInsertElement' ),
}),

/**
* Remove observers on filtered parameter list
Expand All @@ -129,13 +129,11 @@ export default Ember.Component.extend({
* @observes "willClearRender" event
* @returns {void}
*/
unregisterObservers: function() {
var self = this;

this.get( 'observedParameters' ).map( function( key ) {
self.removeObserver( key, self, self.setTranslatedString );
unregisterObservers: Ember.on( 'willClearRender', function() {
this.get( 'observedParameters' ).map( key => {
this.removeObserver( key, this, this.setTranslatedString );
});
}.on( 'willClearRender' ),
}),

// -------------------------------------------------------------------------
// Methods
Expand All @@ -146,7 +144,7 @@ export default Ember.Component.extend({
* @function setTranslatedString
* @returns {void}
*/
setTranslatedString: function() {
setTranslatedString() {
this.set( 'translatedString', this.translateString() );
},

Expand All @@ -155,17 +153,17 @@ export default Ember.Component.extend({
*
* Supports
* - singular/plural string substitution
* - replacement of placeholder tokens in translation strings with passed parameters
* - replacement of placeholder tokens in translation strings with
* passed parameters
*
* @function translateString
* @returns {Ember.String} Translated string
*/
translateString: function() {
var parametersHash = {},
self = this;
translateString() {
var parametersHash = {};

this.get( 'parameters' ).map( function( key ) {
parametersHash[key] = self.get( key );
this.get( 'parameters' ).map( key => {
parametersHash[key] = this.get( key );
});

return this.get( 'translateService' ).translateKey({
Expand Down
9 changes: 6 additions & 3 deletions addon/initializers/translate-service.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import TranslateService from '../services/translate';
* @class translate-service
*/
export default function( container, app ) {
var translateService = TranslateService.create();
var translateService = TranslateService.create();

// Inject Translate Service
container.register( 'translateService:main', translateService, { instantiate: false } );
container.register( 'translateService:main', translateService, {
instantiate: false
});

app.inject( 'view', 'translateService', 'translateService:main' );
app.inject( 'controller', 'translateService', 'translateService:main' );
app.inject( 'component', 'translateService', 'translateService:main' );
}
}
6 changes: 3 additions & 3 deletions addon/mixins/sl-get-translation.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default Ember.Mixin.create({
* @argument {Ember.String} key property to retrieve
* @returns {Ember.String}
*/
get: function( key ) {
get( key ) {
var translationsRegex = /translate\.(.*)/,
matches = key.match( translationsRegex );

Expand All @@ -48,7 +48,7 @@ export default Ember.Mixin.create({
* @argument {Ember.String} key key to translate
* @returns {Ember.String} translated key
*/
translate: function( key ) {
translate( key ) {
return this.translateService.getKeyValue( key );
}
});
});
14 changes: 6 additions & 8 deletions addon/services/translate.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ export default Ember.Object.extend({
* @throws {Ember.assert}
* @returns {void}
*/
setDictionary: function( translations ) {

setDictionary( translations ) {
Ember.assert(
'services/translation.setDictionary() expects parameter to be an object',
'object' === typeof translations && !Array.isArray( translations )
Expand All @@ -60,7 +59,7 @@ export default Ember.Object.extend({
* @argument {Ember.String} key Dictionary key to retrieve value for
* @returns {Ember.String}
*/
getKeyValue: function( key ) {
getKeyValue( key ) {
var defaultKeyValue = 'KEY__NOT__PRESENT',
retrievedKey = this.get( 'dictionary' ).getWithDefault( key, defaultKeyValue ),
returnValue;
Expand Down Expand Up @@ -97,18 +96,17 @@ export default Ember.Object.extend({
* }
* @return {Ember.String} Translated string
*/
translateKey: function( data ) {
translateKey( data ) {

Ember.assert( 'Argument must be an object', 'object' === typeof data && !Array.isArray( data ) );

data.parameters = data.parameters || {};

var pluralErrorTracker = 0,
self = this,
token = data.key,
getTokenValue = function( value ) {
getTokenValue = ( value ) => {
try {
value = self.getKeyValue( value );
value = this.getKeyValue( value );
} catch ( e ) {
Ember.warn( 'Unable to translate key "' + value + '".' );
}
Expand Down Expand Up @@ -141,7 +139,7 @@ export default Ember.Object.extend({
translatedString = getTokenValue( token );

// Parameter replacement
Ember.keys( data.parameters ).map( function( key ) {
Ember.keys( data.parameters ).map( key => {
translatedString = translatedString.replace( '{' + key.replace( '$', '' ) + '}' , data.parameters[key] );
});

Expand Down
2 changes: 1 addition & 1 deletion addon/templates/components/sl-translate.hbs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{translatedString}}
{{translatedString}}
20 changes: 9 additions & 11 deletions bower.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
{
"name": "sl-ember-translate",
"dependencies": {
"handlebars": "~1.3.0",
"jquery": "^1.11.1",
"ember": "1.8.1",
"ember-data": "1.0.0-beta.14.1",
"ember-resolver": "~0.1.11",
"loader.js": "ember-cli/loader.js#1.0.1",
"blanket": "~1.1.5",
"ember": "1.11.1",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli/ember-cli-test-loader#0.1.1",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2",
"ember-qunit": "0.2.8",
"ember-cli-test-loader": "ember-cli/ember-cli-test-loader#0.1.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.1.4",
"ember-qunit": "0.3.1",
"ember-qunit-notifications": "0.0.7",
"qunit": "~1.17.1",
"blanket": "~1.1.5"
"ember-resolver": "~0.1.15",
"jquery": "^1.11.1",
"loader.js": "ember-cli/loader.js#3.2.0",
"qunit": "~1.17.1"
}
}
Empty file modified index.js
100755 → 100644
Empty file.
25 changes: 12 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "ember server",
"build": "ember build",
"test": "ember test"
"test": "ember try:testall"
},
"homepage": "http://softlayer.github.io/sl-ember-translate/",
"repository": {
Expand All @@ -28,25 +28,24 @@
"author": "Jeremy Brown <jeremy@notmessenger.com> (http://www.notmessenger.com)",
"license": "MIT",
"dependencies": {
"ember-cli-babel": "^5.0.0",
"ember-cli-htmlbars": "0.7.4",
"rimraf": "2.3.0"
},
"devDependencies": {
"broccoli-asset-rev": "^2.0.0",
"broccoli-ember-hbs-template-compiler": "^1.6.1",
"broccoli-asset-rev": "^2.0.2",
"broccoli-string-replace": "0.0.2",
"ember-cli": "0.1.15",
"ember-cli-app-version": "0.3.1",
"ember-cli-babel": "^4.0.0",
"ember-cli-blanket": "0.3.2",
"ember-cli-dependency-checker": "0.0.7",
"ember-cli": "0.2.3",
"ember-cli-app-version": "0.3.3",
"ember-cli-blanket": "0.4.0",
"ember-cli-dependency-checker": "0.0.8",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.7",
"ember-cli-qunit": "0.3.10",
"ember-cli-uglify": "1.0.1",
"ember-data": "1.0.0-beta.14.1",
"ember-export-application-global": "^1.0.2",
"express": "^4.8.5",
"glob": "^4.5.1",
"sl-ember-test-helpers": "1.3.0"
"ember-disable-prototype-extensions": "^1.0.0",
"ember-try": "0.0.4",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this entry

"sl-ember-test-helpers": "1.4.0"
}
}
Empty file modified tests/.jshintrc
100755 → 100644
Empty file.
Loading