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
-- returnstrue
if the original value is among the given literals (testing using===
)encodeURIComponent
-- callsencodeURIComponent
on the original valueencodeURI
-- callsencodeURI
on the original valuefmt
-- pass the original values into a format-stringhtmlEscape
-- escapes the original value withHandlebars.Utils.escapeExpression
and wraps the result in aHandlebars.SafeString
(since it's now safe)ifNull
-- fall back on a default valuenotAmong
-- inverse ofamong
notEqual
-- inverse of the built-inequal
macronotMatch
-- inverse of the built-inmatch
macropromise
-- wraps the original value in an already-resolved promisesafeString
-- wraps the original value in aHandlebars.SafeString
join
-- 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.