ember-moment
Advanced tools
Comparing version 1.0.0 to 1.1.0
import moment from './computeds/moment'; | ||
import ago from './computeds/ago'; | ||
import duration from './computeds/duration'; | ||
export { | ||
moment, | ||
ago | ||
ago, | ||
duration | ||
}; |
@@ -10,5 +10,5 @@ import Ember from 'ember'; | ||
var args = [date]; | ||
var momentArgs, computed, desc, input; | ||
computed = emberComputed(date, function () { | ||
var computed = emberComputed(date, function () { | ||
var momentArgs, desc, input; | ||
momentArgs = [get(this, date)]; | ||
@@ -15,0 +15,0 @@ |
@@ -21,3 +21,3 @@ import Ember from 'ember'; | ||
var args = a_slice.call(arguments); | ||
var computed, self, momentArgs, desc; | ||
var computed; | ||
@@ -27,4 +27,5 @@ args.shift(); | ||
return computed = emberComputed(date, function () { | ||
self = this; | ||
momentArgs = [get(this, date)]; | ||
var desc, | ||
self = this, | ||
momentArgs = [get(this, date)]; | ||
@@ -31,0 +32,0 @@ var propertyValues = EnumerableUtils.map(args, function (arg) { |
import Ember from 'ember'; | ||
import moment from 'moment'; | ||
function ago(value, maybeInput) { | ||
var length = arguments.length; | ||
var args = [value]; | ||
var ago; | ||
if (length === 1) { | ||
throw new TypeError('Invalid Number of arguments, expected atleast 1'); | ||
} else if (length > 3) { | ||
args.push(maybeInput); | ||
} | ||
if (Ember.HTMLBars) { | ||
ago = function ago(params) { | ||
if (params.length === 0) { | ||
throw new TypeError('Invalid Number of arguments, expected at least 1'); | ||
} | ||
return moment.apply(this, args).fromNow(); | ||
return moment.apply(this, params).fromNow(); | ||
}; | ||
} else { | ||
ago = function ago(value, maybeInput) { | ||
var length = arguments.length; | ||
var args = [value]; | ||
if (length === 1) { | ||
throw new TypeError('Invalid Number of arguments, expected at least 1'); | ||
} else if (length > 3) { | ||
args.push(maybeInput); | ||
} | ||
return moment.apply(this, args).fromNow(); | ||
}; | ||
} | ||
export { | ||
ago | ||
}; | ||
export default Ember.Handlebars.makeBoundHelper(ago); | ||
export default ago; |
import Ember from 'ember'; | ||
import momentjs from 'moment'; | ||
function moment(value, maybeOutput, maybeInput) { | ||
var length = arguments.length; | ||
var args = []; | ||
var output; | ||
var moment; | ||
if (length === 1 || length > 4) { | ||
// there's one extra argument that handlebars adds to the end, | ||
// which explains the difference in what we are checking and the error we are raising | ||
throw new TypeError('Invalid Number of arguments, expected at least 1 and at most 3'); | ||
} | ||
if (Ember.HTMLBars) { | ||
moment = function moment(params) { | ||
var length = params.length; | ||
var args = []; | ||
var output; | ||
args.push(value); | ||
if (length === 0 || length > 3) { | ||
throw new TypeError('Invalid Number of arguments, expected at least 1 and at most 3'); | ||
} | ||
if (length === 2) { | ||
output = 'LLLL'; | ||
} | ||
else if (length === 3) { | ||
output = maybeOutput; | ||
} else if (length > 3) { | ||
args.push(maybeInput); | ||
output = maybeOutput; | ||
} | ||
args.push(params[0]); | ||
return momentjs.apply(this, args).format(output); | ||
if (length === 1) { | ||
output = 'LLLL'; | ||
} else if (length === 2) { | ||
output = params[1]; | ||
} else if (length > 2) { | ||
args.push(params[2]); | ||
output = params[1]; | ||
} | ||
return momentjs.apply(this, args).format(output); | ||
}; | ||
} else { | ||
moment = function moment(value, maybeOutput, maybeInput) { | ||
var length = arguments.length; | ||
var args = []; | ||
var output; | ||
if (length === 1 || length > 4) { | ||
// there's one extra argument that handlebars adds to the end, | ||
// which explains the difference in what we are checking and the error we are raising | ||
throw new TypeError('Invalid Number of arguments, expected at least 1 and at most 3'); | ||
} | ||
args.push(value); | ||
if (length === 2) { | ||
output = 'LLLL'; | ||
} | ||
else if (length === 3) { | ||
output = maybeOutput; | ||
} else if (length > 3) { | ||
args.push(maybeInput); | ||
output = maybeOutput; | ||
} | ||
return momentjs.apply(this, args).format(output); | ||
}; | ||
} | ||
export { | ||
moment | ||
}; | ||
export default Ember.Handlebars.makeBoundHelper(moment); | ||
export default moment; |
@@ -1,8 +0,18 @@ | ||
import { moment } from 'ember-moment/helpers/moment'; | ||
import { ago } from 'ember-moment/helpers/ago'; | ||
import moment from 'ember-moment/helpers/moment'; | ||
import ago from 'ember-moment/helpers/ago'; | ||
import duration from 'ember-moment/helpers/duration'; | ||
import Ember from 'ember'; | ||
export var initialize = function(/* container, app */) { | ||
Ember.Handlebars.helper('moment', moment); | ||
Ember.Handlebars.helper('ago', ago); | ||
var helper; | ||
if (Ember.HTMLBars) { | ||
helper = Ember.HTMLBars._registerHelper; | ||
} else { | ||
helper = Ember.Handlebars.helper; | ||
}; | ||
helper('moment', moment); | ||
helper('ago', ago); | ||
helper('duration', duration); | ||
}; | ||
@@ -9,0 +19,0 @@ |
{ | ||
"name": "dummy", | ||
"name": "ember-moment", | ||
"dependencies": { | ||
"handlebars": "~1.3.0", | ||
"jquery": "^1.11.1", | ||
"ember": "1.7.0", | ||
"ember-resolver": "~0.1.7", | ||
"loader": "stefanpenner/loader.js#1.0.1", | ||
"ember": "1.8.1", | ||
"ember-resolver": "~0.1.10", | ||
"loader.js": "stefanpenner/loader.js#1.0.1", | ||
"ember-cli-moment-shim": "jasonmit/ember-cli-moment-shim#0.0.2", | ||
"ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.3", | ||
"ember-cli-test-loader": "rwjblue/ember-cli-test-loader#0.0.4", | ||
"ember-cli-test-loader": "ember-cli/ember-cli-test-loader#0.1.1", | ||
"ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2", | ||
"ember-qunit": "0.1.8", | ||
"ember-qunit-notifications": "0.0.4", | ||
"moment": "~2.8.3", | ||
"qunit": "~1.15.0" | ||
"ember-qunit": "0.2.8", | ||
"ember-qunit-notifications": "0.0.7", | ||
"moment": "~2.8.4", | ||
"qunit": "~1.17.1" | ||
}, | ||
"devDependencies": { | ||
"moment-timezone": "~0.2.2" | ||
"moment-timezone": "~0.2.5" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
/* jshint node: true */ | ||
/* global require, module */ | ||
@@ -2,0 +3,0 @@ |
@@ -0,1 +1,7 @@ | ||
### 1.1.0 | ||
* [ENHANCEMENT] HTMLBars support (backwards compat. with Handlebars) | ||
* [ENHANCEMENT] Adding duration helper with examples in the dummy app | ||
### 1.0.0 | ||
@@ -2,0 +8,0 @@ |
@@ -1,2 +0,2 @@ | ||
'user strict'; | ||
'use strict'; | ||
@@ -3,0 +3,0 @@ var path = require('path'); |
{ | ||
"name": "ember-moment", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Moment.js template helpers for ember", | ||
@@ -21,10 +21,9 @@ "directories": { | ||
"devDependencies": { | ||
"body-parser": "^1.2.0", | ||
"broccoli-asset-rev": "0.1.1", | ||
"broccoli-asset-rev": "^2.0.0", | ||
"broccoli-ember-hbs-template-compiler": "^1.6.1", | ||
"ember-cli": "0.0.46", | ||
"ember-cli": "0.1.15", | ||
"ember-cli-dependency-checker": "0.0.7", | ||
"ember-cli-ic-ajax": "0.1.1", | ||
"ember-cli-inject-live-reload": "^1.0.2", | ||
"ember-cli-qunit": "0.1.0", | ||
"ember-data": "1.0.0-beta.10", | ||
"ember-cli-inject-live-reload": "^1.3.0", | ||
"ember-cli-qunit": "0.3.7", | ||
"express": "^4.8.5", | ||
@@ -31,0 +30,0 @@ "glob": "^4.0.5" |
# Ember-moment | ||
[moment.js](momentjs.com) template helpers for ember [![Build Status](https://travis-ci.org/stefanpenner/ember-moment.svg?branch=master)](https://travis-ci.org/stefanpenner/ember-moment) | ||
[moment.js](http://momentjs.com) template helpers for ember [![Build Status](https://travis-ci.org/stefanpenner/ember-moment.svg?branch=master)](https://travis-ci.org/stefanpenner/ember-moment) | ||
## Usage | ||
* `npm install --save ember-moment` | ||
* `ember g ember-moment` | ||
* `ember install:addon ember-moment` | ||
@@ -13,2 +12,3 @@ ```hbs | ||
{{ago date}} | ||
{{duration ms}} | ||
``` | ||
@@ -19,4 +19,5 @@ | ||
```hbs | ||
{{moment date inputFormat outputFormat}} | ||
{{moment date outputFormat inputFormat}} | ||
{{ago date inputFormat}}} | ||
{{duration number units}} | ||
``` | ||
@@ -23,0 +24,0 @@ |
import Ember from 'ember'; | ||
import { moment, ago } from 'ember-moment/computed'; | ||
import { moment, ago, duration } from 'ember-moment/computed'; | ||
@@ -8,5 +8,7 @@ export default Ember.Controller.extend({ | ||
date: new Date(), | ||
numHours: 822, | ||
computedDate: moment('date', 'MM/DD/YY hh:mm:ss'), | ||
computedOneHourAgo: ago('lastHour'), | ||
computedNumHours: duration('numHours', 'hours'), | ||
usIndependenceDay: new Date(1776, 6, 4, 12, 0, 0) | ||
}); |
@@ -33,3 +33,3 @@ /* jshint node: true */ | ||
ENV.baseURL = '/'; | ||
ENV.locationType = 'auto'; | ||
ENV.locationType = 'none'; | ||
@@ -36,0 +36,0 @@ // keep test console output quieter |
@@ -1,3 +0,2 @@ | ||
# robotstxt.org/ | ||
# http://www.robotstxt.org | ||
User-agent: * |
import Ember from 'ember'; | ||
import Application from '../../app'; | ||
import Router from '../../router'; | ||
import config from '../../config/environments/test'; | ||
import config from '../../config/environment'; | ||
@@ -12,6 +12,2 @@ export default function startApp(attrs) { | ||
Router.reopen({ | ||
location: 'none' | ||
}); | ||
Ember.run(function() { | ||
@@ -23,5 +19,3 @@ App = Application.create(attributes); | ||
App.reset(); // this shouldn't be needed, i want to be able to "start an app at a specific URL" | ||
return App; | ||
} |
@@ -11,6 +11,3 @@ import resolver from './helpers/resolver'; | ||
QUnit.config.urlConfig.push({ id: 'nocontainer', label: 'Hide container'}); | ||
if (QUnit.urlParams.nocontainer) { | ||
document.getElementById('ember-testing-container').style.visibility = 'hidden'; | ||
} else { | ||
document.getElementById('ember-testing-container').style.visibility = 'visible'; | ||
} | ||
var containerVisibility = QUnit.urlParams.nocontainer ? 'hidden' : 'visible'; | ||
document.getElementById('ember-testing-container').style.visibility = containerVisibility; |
@@ -6,3 +6,3 @@ import Ember from 'ember'; | ||
module('momentComputed'); | ||
module('agoComputed'); | ||
@@ -9,0 +9,0 @@ var createSubject = function (attrs) { |
import date from './date'; | ||
import { | ||
ago | ||
} from 'ember-moment/helpers/ago'; | ||
import ago from 'ember-moment/helpers/ago'; | ||
import callHelper from '../../helpers/call-helper'; | ||
@@ -11,9 +10,9 @@ module('AgoHelper'); | ||
test('one arg (date)', function() { | ||
equal(ago(date(0), FAKE_HANDLEBARS_CONTEXT), "45 years ago"); | ||
equal(ago(date(), FAKE_HANDLEBARS_CONTEXT), 'a few seconds ago'); | ||
equal(callHelper(ago, [date(0), FAKE_HANDLEBARS_CONTEXT]), "45 years ago"); | ||
equal(callHelper(ago, [date(), FAKE_HANDLEBARS_CONTEXT]), 'a few seconds ago'); | ||
}); | ||
test('two args (date, inputFormat)', function() { | ||
equal(ago(date(0), 'LLLL', FAKE_HANDLEBARS_CONTEXT), '45 years ago'); | ||
equal(ago(date(), 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'a few seconds ago'); | ||
equal(callHelper(ago, [date(0), 'LLLL', FAKE_HANDLEBARS_CONTEXT]), '45 years ago'); | ||
equal(callHelper(ago, [date(), 'LLLL', FAKE_HANDLEBARS_CONTEXT]), 'a few seconds ago'); | ||
}); |
import date from './date'; | ||
import { | ||
moment | ||
} from 'ember-moment/helpers/moment'; | ||
import moment from 'ember-moment/helpers/moment'; | ||
import callHelper from '../../helpers/call-helper'; | ||
@@ -11,16 +10,16 @@ module('MomentHelper'); | ||
test('one arg (date)', function() { | ||
equal(moment(date(new Date(0)), FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:00 PM'); | ||
equal(moment(date(new Date(60*60*24)), FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:01 PM'); | ||
equal(callHelper(moment, [date(date(0)), FAKE_HANDLEBARS_CONTEXT]), 'Wednesday, December 31, 1969 7:00 PM'); | ||
equal(callHelper(moment, [date(date(60*60*24)), FAKE_HANDLEBARS_CONTEXT]), 'Wednesday, December 31, 1969 7:01 PM'); | ||
}); | ||
test('two args (date, outputFormat)', function() { | ||
equal(moment(date(new Date(0)), 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:00 PM'); | ||
equal(moment(date(new Date(60*60*24)), 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:01 PM'); | ||
equal(moment(Date.parse('2011-10-10T14:48:00-05:00'), 'MMMM D, YYYY', FAKE_HANDLEBARS_CONTEXT), 'October 10, 2011'); | ||
equal(callHelper(moment, [date(date(0)), 'LLLL', FAKE_HANDLEBARS_CONTEXT]), 'Wednesday, December 31, 1969 7:00 PM'); | ||
equal(callHelper(moment, [date(date(60*60*24)), 'LLLL', FAKE_HANDLEBARS_CONTEXT]), 'Wednesday, December 31, 1969 7:01 PM'); | ||
equal(callHelper(moment, [date(Date.parse('2011-10-10T14:48:00-05:00')), 'MMMM D, YYYY', FAKE_HANDLEBARS_CONTEXT]), 'October 10, 2011'); | ||
}); | ||
test('three args (date, outputFormat, inputFormat)', function() { | ||
equal(moment('October 10, 2011', 'LLLL', 'MMMM D, YYYY', FAKE_HANDLEBARS_CONTEXT), 'Monday, October 10, 2011 12:00 AM'); | ||
equal(moment('5/3/10', 'MMMM D, YYYY', 'M/D/YY', FAKE_HANDLEBARS_CONTEXT), 'May 3, 2010'); | ||
equal(moment(date(new Date(0)), 'LLLL', 'LLLL', FAKE_HANDLEBARS_CONTEXT), 'Wednesday, December 31, 1969 7:00 PM'); | ||
equal(callHelper(moment, ['October 10, 2011', 'LLLL', 'MMMM D, YYYY', FAKE_HANDLEBARS_CONTEXT]), 'Monday, October 10, 2011 12:00 AM'); | ||
equal(callHelper(moment, ['5/3/10', 'MMMM D, YYYY', 'M/D/YY', FAKE_HANDLEBARS_CONTEXT]), 'May 3, 2010'); | ||
equal(callHelper(moment, [date(date(0)), 'LLLL', 'LLLL', FAKE_HANDLEBARS_CONTEXT]), 'Wednesday, December 31, 1969 7:00 PM'); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
31837
9
64
615
53