Last active
August 29, 2015 14:00
-
-
Save digitalplaywright/11388029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Handlebars.registerHelper("can", function(actor, action, object, fn) | |
{ | |
var context = (fn.contexts && fn.contexts[0]) || this; | |
var canAction = function(can_args) | |
{ | |
var rules = context.container.lookup('rules:eval'); | |
return rules.can({activity: can_args[1], actor: can_args[0], object: can_args[2] }); | |
}; | |
var args = [actor, action ,object, fn]; | |
var options = args.pop(); | |
// Gather all bound property names to pass in order to observe them | |
var properties = options.types.reduce(function(results, type, index) { | |
if (type === 'ID') { | |
results.push(args[index]); | |
} | |
return results; | |
}, []); | |
// Resolve actual values for all params to pass to the conditional callback | |
var normalizer = function() { | |
return Ember.Handlebars.resolveParams(context, args, options); | |
}; | |
return Ember.Handlebars.bind.call(context, 'content', options, true, canAction, normalizer, properties ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment