ember-cli-moment-shim
Advanced tools
Comparing version 0.4.0 to 0.5.0
45
index.js
@@ -11,17 +11,2 @@ 'use strict'; | ||
function makeArray(obj) { | ||
if (Array.isArray(obj)) { | ||
return obj; | ||
} | ||
if (typeof obj === 'undefined') { | ||
obj = []; | ||
} | ||
else { | ||
obj = [obj]; | ||
} | ||
return obj; | ||
} | ||
module.exports = { | ||
@@ -50,3 +35,13 @@ name: 'moment', | ||
app.import(path.join(vendor, 'moment', 'min', 'moment.min.js')); | ||
if (typeof options.includeLocales === 'boolean' && options.includeLocales) { | ||
app.import(path.join(vendor, 'moment', 'min', 'moment-with-locales.min.js')); | ||
} | ||
else { | ||
app.import(path.join(vendor, 'moment', 'min', 'moment.min.js')); | ||
if (Array.isArray(options.includeLocales)) { | ||
options.includeLocales.map(function(locale) { | ||
app.import(path.join(vendor, 'moment', 'locales', locale + '.js')) | ||
}); | ||
} | ||
} | ||
@@ -56,6 +51,2 @@ if (options.includeTimezone) { | ||
} | ||
options.includeLocales.map(function(locale) { | ||
app.import(path.join(vendor, 'moment', 'locales', locale + '.js')) | ||
}); | ||
}, | ||
@@ -71,7 +62,9 @@ | ||
config.includeLocales = makeArray(config.includeLocales).filter(function(locale) { | ||
return typeof locale === 'string'; | ||
}).map(function(locale) { | ||
return locale.replace('.js', '').trim().toLowerCase(); | ||
}); | ||
if (Array.isArray(config.includeLocales)) { | ||
config.includeLocales = config.includeLocales.filter(function(locale) { | ||
return typeof locale === 'string'; | ||
}).map(function(locale) { | ||
return locale.replace('.js', '').trim().toLowerCase(); | ||
}); | ||
} | ||
@@ -97,3 +90,3 @@ return config; | ||
if (options.includeLocales.length) { | ||
if (Array.isArray(options.includeLocales) && options.includeLocales.length) { | ||
trees.push(new Funnel(momentPath, { | ||
@@ -100,0 +93,0 @@ srcDir: 'locale', |
{ | ||
"name": "ember-cli-moment-shim", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "Brings moment and moment-timezone into your Ember applications", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -31,4 +31,6 @@ # ember-cli-moment-shim | ||
## Include moment locales for i18n support | ||
## i18n support | ||
### Cherry pick locales (optimal) | ||
```js | ||
@@ -46,3 +48,17 @@ // config.environment.js | ||
### Include all locales | ||
```js | ||
// config.environment.js | ||
module.exports = function(environment) { | ||
return { | ||
moment: { | ||
includeLocales: true | ||
} | ||
}; | ||
``` | ||
### Configure default runtime locale | ||
```js | ||
// app/routes/applicaton.js | ||
@@ -49,0 +65,0 @@ import moment from 'moment'; |
11137
78
215