Computed Property Macros for Ember
Ember. Versions between 0.9.8 and 1.x should work fine. (If you're running Ember 0.9.x and want the CP macros from Ember 1.0, the ember_09 branch has them.)
Just add ember-cpm.js to your page after Ember but before your app.
You will need to install the dependencies first. Run make install_dependencies to do it.
Then run make to generate ember-cpm.js from source in the dist folder.
To run the rest suite in interactive mode execute make test and enter http://localhost:4200.
To run the test suite just once and exit run make test-ci.
You can also run the test suite in watch mode with broccoli serve.
For run the tests once in just type make test.
You can also run the tests in interactive mode by typing testem.
Ember-CPM will likely see several breaking changes during Q2 and Q3 2014 as its scope and structure change. We will, of course, bump the major version when making breaking changes and make the period of instability as short as possible.
among-- returnstrueif the original value is among the given literals (testing using===)encodeURIComponent-- callsencodeURIComponenton the original valueencodeURI-- callsencodeURIon the original valuefmt-- pass the original values into a format-stringhtmlEscape-- escapes the original value withHandlebars.Utils.escapeExpressionand wraps the result in aHandlebars.SafeString(since it's now safe)ifNull-- fall back on a default valuenotAmong-- inverse ofamongnotEqual-- inverse of the built-inequalmacronotMatch-- inverse of the built-inmatchmacropromise-- wraps the original value in an already-resolved promisesafeString-- wraps the original value in aHandlebars.SafeStringjoin-- joins the supplied values together with a provided sepatatorsumBy-- sums a property from an array of objects
Person = Ember.Object.extend({
name: null,
handedness: null,
greeting: null,
handle: EmberCPM.Macros.ifNull('name', 'Anonymous'),
greeting: EmberCPM.Macros.fmt('name', 'greeting', '%@ says, "%@!"'),
canUseLeftHand: EmberCPM.Macros.among('handedness', 'left', 'ambidextrous'),
notNamedJohn: EmberCPM.Macros.notMatch('name', /\bJohn\b/)
});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.
