Computed Property Macros for Ember
Ember. Versions between 0.9.8 and 1.1 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 index.js
to your page after Ember but before your app.
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 value into a format-stringhtmlEscape
-- escapes the original value withifNull
-- fall back on a default valueHandlebars.Utils.escapeExpression
and wraps the result in aHandlebars.SafeString
(since it's now safe)notAmong
-- 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
Person = Ember.Object.extend({
name: null,
handedness: null,
handle: EmberCPM.Macros.ifNull('name', 'Anonymous'),
greeting: EmberCPM.Macros.fmt('name', '%@ says, "Hello!"'),
canUseLeftHand: EmberCPM.Macros.among('handedness', 'left', 'ambidextrous'),
notNamedJohn: EmberCPM.Macros.notMach('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.