mirror of
				https://github.com/ether/etherpad-lite.git
				synced 2025-11-04 02:01:30 +01:00 
			
		
		
		
	use hook name as function name, if not specified
Example `"[hookName]": "ep_plugin/static/js/index:[hookName]"` becomes `"[hookName]": "ep_plugin/static/js/index"`
This commit is contained in:
		
							parent
							
								
									49593a1c8e
								
							
						
					
					
						commit
						5115f74f66
					
				@ -51,10 +51,12 @@ exports.formatHooks = function () {
 | 
			
		||||
  return res.join("\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.loadFn = function (path) {
 | 
			
		||||
exports.loadFn = function (path, hookName) {
 | 
			
		||||
  var x = path.split(":");
 | 
			
		||||
  var fn = require(x[0]);
 | 
			
		||||
  _.each(x[1].split("."), function (name) {
 | 
			
		||||
  var functionName = x[1] ? x[1] : hookName;  
 | 
			
		||||
  
 | 
			
		||||
  _.each(functionName.split("."), function (name) {
 | 
			
		||||
    fn = fn[name];
 | 
			
		||||
  });
 | 
			
		||||
  return fn;
 | 
			
		||||
@ -63,14 +65,18 @@ exports.loadFn = function (path) {
 | 
			
		||||
exports.extractHooks = function (parts, hook_set_name) {
 | 
			
		||||
  var hooks = {};
 | 
			
		||||
  _.each(parts,function (part) {
 | 
			
		||||
    _.chain(part[hook_set_name] || {}).keys().each(function (hook_name) {
 | 
			
		||||
    _.chain(part[hook_set_name] || {})
 | 
			
		||||
    .keys()
 | 
			
		||||
    .each(function (hook_name) {
 | 
			
		||||
      if (hooks[hook_name] === undefined) hooks[hook_name] = [];
 | 
			
		||||
      
 | 
			
		||||
      
 | 
			
		||||
      var hook_fn_name = part[hook_set_name][hook_name];
 | 
			
		||||
      var hook_fn = exports.loadFn(part[hook_set_name][hook_name]);
 | 
			
		||||
      var hook_fn = exports.loadFn(hook_fn_name, hook_name);
 | 
			
		||||
      if (hook_fn) {
 | 
			
		||||
        hooks[hook_name].push({"hook_name": hook_name, "hook_fn": hook_fn, "hook_fn_name": hook_fn_name, "part": part});
 | 
			
		||||
      } else {
 | 
			
		||||
	console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]);
 | 
			
		||||
        console.error("Unable to load hook function for " + part.full_name + " for hook " + hook_name + ": " + part.hooks[hook_name]);
 | 
			
		||||
      }	
 | 
			
		||||
    });
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user