Skip to content

Commit

Permalink
Merge pull request #145 from cibernox/prepare-release-3-0
Browse files Browse the repository at this point in the history
Prepare 3.0 release
  • Loading branch information
cibernox authored Jan 20, 2017
2 parents 331db4b + e5f4e5d commit 66c6621
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 77 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ cache:

env:
# we recommend testing LTS's and latest stable release (bonus points to beta/canary)
- EMBER_TRY_SCENARIO=ember-1.13
- EMBER_TRY_SCENARIO=ember-lts-2.4
- EMBER_TRY_SCENARIO=ember-lts-2.8
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
Expand Down
44 changes: 7 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@ Computed Property Macros for Ember
### Requirements

Version 2.0+ will only work with Ember 2.0+
If you are using Ember 1.X stay in user ember-cpm 1.X too.

### Installation

If you are using [Ember CLI](https://github.com/stefanpenner/ember-cli), you can install ember-cpm as
an addon with `npm install ember-cpm --save-dev` and you will be able to import native ES modules from
within your app.
Just run `ember install ember-cpm`

If not, you need to add `ember-cpm.js` manually to your project.

You can find the latest versions of ember-cpm in [the S3 bucket](http://ember-cpm-builds.s3-website-us-east-1.amazonaws.com/) in two flavours: globals or AMD.
Alternatively, you can also build from source. See [Contributing](https://github.com/cibernox/ember-cpm#contributing) for more info about how to build from source.
If you use the global build, an `EmberCPM` global should be available.

### Usage

In Ember CLI:
Just import individual macros from `ember-cpm/macros/*` or all macros from `ember-cpm`.

```js
// Import only one macros
Expand All @@ -37,27 +29,10 @@ import ifNull from "ember-cpm/macros/if-null";
import EmberCPM from "ember-cpm";
```

In any other scenario, include `ember-cpm.js` after ember but before your app, and a gobal will be available:

```js
Person = Ember.Object.extend({
name: null,
handle: EmberCPM.Macros.ifNull('name', 'Anonymous'),
});
```

### Contributing

You have to install Ember CLI to build this library. If you don't have it, visit [www.ember-cli.com/](http://www.ember-cli.com/) for further guidance about how to install it.

After running `npm install` to get all the dependencies you can:

* Run `ember serve` and go to `localhost:4200/test` to run the tests in watch mode. You can also run `ember serve --docs` to see generate and expose documentation in `/docs`.
* Run `ember test` to run all tests once (requires phantomjs).
* Run `ember build` to build from source.
* Run `ember yuidoc` to generate all the documentation inside the `/docs` folder

#### Generating new computed property macros with ember-cli
To generate a new computed property macros with ember-cli

* Run `ember g macro <dasherized-macro-name>`. This will generate a few files
* `./addon/macros/dasherized-macro-name.js` (the macro)
Expand Down Expand Up @@ -102,13 +77,15 @@ var Macros = {
* `computedPromise` -- Updates computed property when supplied callback (which must return a promise) is resolved

### Composable Computed Property Macros
`conditional`, `sum`, `quotient` and `product` have support for *composable* computed property macros. This allows developers to mix other macros together without defining a bunch of otherwise-useless intermediate properties

Unlike Ember's computed property macros, the macros in this addon are *composable*. That means
you define macros inside other macros without defining them in a separate key.

```javascript
import Ember from 'ember';
import EmberCPM from 'ember-cpm';

const { Macros: { sum, difference, product }} = EmberCPM;
const { Macros: { sum, difference, product } } = EmberCPM;

export default Ember.Component.extend({
num1: 45,
Expand All @@ -122,11 +99,4 @@ export default Ember.Component.extend({
product(difference('num2', 'num1'), 'num4')
)
});

```

### `Ember.computed`

If you would prefer to use `Ember.computed.{macro}` instead of
`EmberCPM.Macros.{macro}` (for the sake of uniform access), simply call
`EmberCPM.install()` before your application code.
15 changes: 2 additions & 13 deletions addon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ import asFloat from './macros/as-float';
import asInt from './macros/as-int';
import computedPromise from './macros/computed-promise';

function reverseMerge(dest, source) {
for (var key in source) {
if (source.hasOwnProperty(key) && !dest.hasOwnProperty(key)) {
dest[key] = source[key];
}
}
}

var VERSION = '1.3.1';
var Macros = {
not: not,
Expand All @@ -53,7 +45,6 @@ var Macros = {
product: product,
computedPromise: computedPromise
};
var install = function(){ reverseMerge(Ember.computed, Macros); };


if (Ember.libraries) {
Expand All @@ -62,12 +53,10 @@ if (Ember.libraries) {

export {
VERSION,
Macros,
install
Macros
};

export default {
VERSION: VERSION,
Macros: Macros,
install: install
Macros: Macros
};
17 changes: 3 additions & 14 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,13 @@
module.exports = {
scenarios: [
{
name: 'ember-1.13',
name: 'ember-lts-2.8',
bower: {
dependencies: {
'ember': '~1.13.0'
'ember': 'components/ember#lts-2-8'
},
resolutions: {
'ember': '~1.13.0'
}
}
},
{
name: 'ember-lts-2.4',
bower: {
dependencies: {
'ember': 'components/ember#lts-2-4'
},
resolutions: {
'ember': 'lts-2-4'
'ember': 'lts-2-8'
}
}
},
Expand Down
9 changes: 0 additions & 9 deletions tests/unit/ember-cpm-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { module, test } from "qunit";
import Ember from "ember";
import EmberCPM from "ember-cpm";

module("EmberCPM");
Expand All @@ -14,11 +13,3 @@ test("contains all the macros", function(assert){
assert.equal(typeof EmberCPM.Macros[macroName], "function");
});
});

test("install macros itself into Ember.computed", function(assert){
assert.expect(macrosNames.length);
EmberCPM.install();
macrosNames.forEach(function(macroName){
assert.equal(typeof Ember.computed[macroName], 'function');
});
});
2 changes: 1 addition & 1 deletion tests/unit/macros/html-escape-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ test('HTML-escapes the value', function(assert) {

test('Marks the result as safe', function(assert) {
var actual = MyObj.create({ value: '<img />' }).get('escaped');
assert.equal(actual instanceof Ember.Handlebars.SafeString, true);
assert.ok(Ember.String.isHTMLSafe(actual));
});
2 changes: 1 addition & 1 deletion tests/unit/macros/safe-string-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ test('returns null if the value is null', function(assert) {
test('returns a safe version of the value', function(assert) {
var actual = MyObj.create({ value: 'Wombat' }).get('safe');
assert.equal(actual.toString(), 'Wombat');
assert.equal(actual instanceof Ember.Handlebars.SafeString, true);
assert.ok(Ember.String.isHTMLSafe(actual));
});

0 comments on commit 66c6621

Please sign in to comment.