Use standard Ember.Handlebars.registerBoundHelper.
No need for the custom Ember.registerBoundHelper implementation.
This commit is contained in:
parent
9011f9d85d
commit
f9fe221e9a
|
@ -1,5 +1,3 @@
|
||||||
require 'ext/ember/bound_helper'
|
|
||||||
|
|
||||||
safe = (string) ->
|
safe = (string) ->
|
||||||
new Handlebars.SafeString(string)
|
new Handlebars.SafeString(string)
|
||||||
|
|
||||||
|
@ -125,7 +123,7 @@ Ember.Handlebars.helper('travis-errors', (name, options) ->
|
||||||
Handlebars.registerHelper 'tipsy', (text, tip) ->
|
Handlebars.registerHelper 'tipsy', (text, tip) ->
|
||||||
safe '<span class="tool-tip" original-title="' + tip + '">' + text + '</span>'
|
safe '<span class="tool-tip" original-title="' + tip + '">' + text + '</span>'
|
||||||
|
|
||||||
Ember.registerBoundHelper 'capitalize', (value, options) ->
|
Ember.Handlebars.registerBoundHelper 'capitalize', (value, options) ->
|
||||||
if value?
|
if value?
|
||||||
safe $.capitalize(value)
|
safe $.capitalize(value)
|
||||||
else
|
else
|
||||||
|
@ -140,10 +138,10 @@ Ember.Handlebars.helper('githubCommitLink', (slug, commitSha) ->
|
||||||
safe '<a class="github-link only-on-hover" href="' + url + '">' + sha + '</a>'
|
safe '<a class="github-link only-on-hover" href="' + url + '">' + sha + '</a>'
|
||||||
)
|
)
|
||||||
|
|
||||||
Ember.registerBoundHelper 'formatTime', (value, options) ->
|
Ember.Handlebars.registerBoundHelper 'formatTime', (value, options) ->
|
||||||
safe Travis.Helpers.timeAgoInWords(value) || '-'
|
safe Travis.Helpers.timeAgoInWords(value) || '-'
|
||||||
|
|
||||||
Ember.registerBoundHelper 'formatDuration', (duration, options) ->
|
Ember.Handlebars.registerBoundHelper 'formatDuration', (duration, options) ->
|
||||||
safe Travis.Helpers.timeInWords(duration)
|
safe Travis.Helpers.timeInWords(duration)
|
||||||
|
|
||||||
Ember.Handlebars.helper('formatCommit', (commit) ->
|
Ember.Handlebars.helper('formatCommit', (commit) ->
|
||||||
|
@ -153,16 +151,16 @@ Ember.Handlebars.helper('formatCommit', (commit) ->
|
||||||
Ember.Handlebars.helper 'formatSha', (sha) ->
|
Ember.Handlebars.helper 'formatSha', (sha) ->
|
||||||
safe Travis.Helpers.formatSha(sha)
|
safe Travis.Helpers.formatSha(sha)
|
||||||
|
|
||||||
Ember.registerBoundHelper 'pathFrom', (url, options) ->
|
Ember.Handlebars.registerBoundHelper 'pathFrom', (url, options) ->
|
||||||
safe Travis.Helpers.pathFrom(url)
|
safe Travis.Helpers.pathFrom(url)
|
||||||
|
|
||||||
Ember.Handlebars.helper 'formatMessage', (message, options) ->
|
Ember.Handlebars.helper 'formatMessage', (message, options) ->
|
||||||
safe Travis.Helpers.formatMessage(message, options.hash)
|
safe Travis.Helpers.formatMessage(message, options.hash)
|
||||||
|
|
||||||
Ember.registerBoundHelper 'formatConfig', (config, options) ->
|
Ember.Handlebars.registerBoundHelper 'formatConfig', (config, options) ->
|
||||||
safe Travis.Helpers.formatConfig(config)
|
safe Travis.Helpers.formatConfig(config)
|
||||||
|
|
||||||
Ember.registerBoundHelper 'shortCompareShas', (url, options) ->
|
Ember.Handlebars.registerBoundHelper 'shortCompareShas', (url, options) ->
|
||||||
path = Travis.Helpers.pathFrom(url)
|
path = Travis.Helpers.pathFrom(url)
|
||||||
if path.indexOf('...') >= 0
|
if path.indexOf('...') >= 0
|
||||||
shas = path.split('...')
|
shas = path.split('...')
|
||||||
|
@ -170,7 +168,7 @@ Ember.registerBoundHelper 'shortCompareShas', (url, options) ->
|
||||||
else
|
else
|
||||||
path
|
path
|
||||||
|
|
||||||
Ember.registerBoundHelper 'formatLog', (log, options) ->
|
Ember.Handlebars.registerBoundHelper 'formatLog', (log, options) ->
|
||||||
parentView = @get 'parentView'
|
parentView = @get 'parentView'
|
||||||
repo = parentView.get(options.repo)
|
repo = parentView.get(options.repo)
|
||||||
item = parentView.get(options.item)
|
item = parentView.get(options.item)
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
// https://gist.github.com/2018185
|
|
||||||
// For reference: https://github.com/wagenet/ember.js/blob/ac66dcb8a1cbe91d736074441f853e0da474ee6e/packages/ember-handlebars/lib/views/bound_property_view.js
|
|
||||||
var BoundHelperView = Ember.View.extend(Ember._Metamorph, {
|
|
||||||
|
|
||||||
context: null,
|
|
||||||
options: null,
|
|
||||||
property: null,
|
|
||||||
// paths of the property that are also observed
|
|
||||||
propertyPaths: [],
|
|
||||||
|
|
||||||
value: Ember.K,
|
|
||||||
|
|
||||||
valueForRender: function() {
|
|
||||||
var value = this.value(Ember.get(this.context, this.property), this.options);
|
|
||||||
if (this.options.escaped) { value = Handlebars.Utils.escapeExpression(value); }
|
|
||||||
return value;
|
|
||||||
},
|
|
||||||
|
|
||||||
render: function(buffer) {
|
|
||||||
buffer.push(this.valueForRender());
|
|
||||||
},
|
|
||||||
|
|
||||||
valueDidChange: function() {
|
|
||||||
if (this.morph.isRemoved()) { return; }
|
|
||||||
this.morph.html(this.valueForRender());
|
|
||||||
},
|
|
||||||
|
|
||||||
didInsertElement: function() {
|
|
||||||
this.valueDidChange();
|
|
||||||
},
|
|
||||||
|
|
||||||
init: function() {
|
|
||||||
this._super();
|
|
||||||
Ember.addObserver(this.context, this.property, this, 'valueDidChange');
|
|
||||||
this.get('propertyPaths').forEach(function(propName) {
|
|
||||||
Ember.addObserver(this.context, this.property + '.' + propName, this, 'valueDidChange');
|
|
||||||
}, this);
|
|
||||||
},
|
|
||||||
|
|
||||||
destroy: function() {
|
|
||||||
Ember.removeObserver(this.context, this.property, this, 'valueDidChange');
|
|
||||||
this.get('propertyPaths').forEach(function(propName) {
|
|
||||||
this.context.removeObserver(this.property + '.' + propName, this, 'valueDidChange');
|
|
||||||
}, this);
|
|
||||||
this._super();
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
Ember.registerBoundHelper = function(name, func) {
|
|
||||||
var propertyPaths = Array.prototype.slice.call(arguments, 2);
|
|
||||||
Ember.Handlebars.registerHelper(name, function(property, options) {
|
|
||||||
var data = options.data,
|
|
||||||
view = data.view,
|
|
||||||
ctx = this;
|
|
||||||
|
|
||||||
var bindView = view.createChildView(BoundHelperView, {
|
|
||||||
property: property,
|
|
||||||
propertyPaths: propertyPaths,
|
|
||||||
context: ctx,
|
|
||||||
options: options.hash,
|
|
||||||
value: func
|
|
||||||
});
|
|
||||||
|
|
||||||
view.appendChild(bindView);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user