<commit_before>/**
 * @class Echo.Plugin
 * Foundation class implementing core logic to create plugins and manipulate with them.
 */
Echo.Plugin = function() {};

// static interface
/**
 * @static
 * Function which creates a plugin object using it manifest declaration.
 * 
 * @param {Object} manifest (required) Specifies the plugin interface in the predefined way.
 * @param {String} manifest.name (required) Specifies the Plugin name.
 * @param {Object} [manifest.config] Specifies the configuration data with the ability to define default values.
 * @param {Object} [manifest.labels] Specifies the list of language labels used in the particular plugin UI.
 * @param {Object} [manifest.events] Specifies the list of external events used by plugin.
 * @param {Object} [manifest.methods] Specifies the list of plugin methods.
 * @param {Object} [manifest.renderers] Specifies the list of plugin renderers.
 * @param {Object} [manifest.templates] Specifies the list of plugin templates
 * @param {Function} [manifest.init] Function called during plugin initialization.
 * @param {String} [manifest.css] Specifies the CSS rules for the plugin.
 * @return {Object} generated plugin class
 */
Echo.Plugin.create = function(manifest) {
	var plugin = Echo.Plugin.getClass(manifest.name, manifest.component.name);

	// prevent multiple re-definitions
	if (plugin) return plugin;

	var constructor = function(config) {
		if (!config || !config.component) return;
		var self = this;
		this.name = manifest.name;
		this.component = config.component;
		this.cssClass = this.component.get("cssPrefix") + "plugin-" + manifest.name;
		this.cssPrefix = this.cssClass + "-";

		// define extra css class for the control target
		this.component.config.get("target").addClass(this.cssClass);

		this._init(["config"]);
	};
	constructor.manifest = manifest;
	constructor.dependencies = manifest.dependencies;

	Echo.Utils.inherit(constructor, Echo.Plugin);

	// copy destroy method to the list of methods
	if (manifest.destroy) {
		manifest.methods.destroy = manifest.destroy;
	}

	if (manifest.methods) {
		$.extend(constructor.prototype, manifest.methods);
	}
	Echo.Utils.setNestedValue(
		window,
		Echo.Plugin._getClassName(manifest.name, manifest.component.name),
		constructor
	);
	return constructor;
};

/**
 * @static
 * Method returning common manifest structure.
 * @param {String} name (required) Specifies plugin name.
 * @param {String} component (required) Specifies component name to be extended.
 * @return {Object} Basic plugin manifest declaration.
 */
Echo.Plugin.manifest = function(name, component) {
	return {
		"name": name,
		"component": {
			"name": component,
			"renderers": {}
		},
		"config": {},
		"labels": {},
		"events": {},
		"methods": {},
		"renderers": {},
		"templates": {},
		"dependencies": [],
		"enabled": function() { return true; },
		"init": function(){},
		"destroy": undefined
	};
};

/**
 * @static
 * Checks if plugin is already defined.
 * @param {Object} manifest (required) Plugin manifest.
 * @return {Boolean}
 */
Echo.Plugin.isDefined = function(manifest) {
	return !!Echo.Plugin.getClass(manifest.name, manifest.component.name);
};

/**
 * @static
 * Returns the corresponding plugin by its name and parent component name.
 * @param {String} name {required} Plugin name.
 * @param {String} component {required} Extended component name.
 * @return {Object} Plugin class.
 */
Echo.Plugin.getClass = function(name, component) {
	return Echo.Utils.getNestedValue(window, Echo.Plugin._getClassName(name, component));
};

/**
 *
 * @method
 * Initializes the plugin.
 */
Echo.Plugin.prototype.init = function() {
	this._init([
		"css",
		"events",
		"subscriptions",
		"labels",
		"renderers",
		"dom",
		"launcher"
	]);
};

/**
 *
 * @method
 * Checks if the plugin is enabled.
 */
Echo.Plugin.prototype.enabled = function() {
	if (typeof this._enabled === "undefined") {
		var enabled = this.config.get("enabled", true);
		if ($.isFunction(enabled)) {
			enabled = enabled.call(this);
		}
		// FIXME: should be boolean value (inconsistancy behaviour of the template engine)
		enabled = $.type(enabled) === "string"
			? enabled === "true"
			: enabled;
		this._enabled = enabled && !!this._manifest("enabled").call(this);
	}
	return this._enabled;
};

/**
 * @method
 * @inheritdoc Echo.Control#set
 */
Echo.Plugin.prototype.set = function(key, value) {
	Echo.Utils.setNestedValue(this, key, value);
};

/**
 * @method
 * @inheritdoc Echo.Control#get
 */
Echo.Plugin.prototype.get = function(key, defaults) {
	return Echo.Utils.getNestedValue(this, key, defaults);
};

/**
 * @method
 * @inheritdoc Echo.Control#remove
 */
Echo.Plugin.prototype.remove = function(key) {
	this.set(key, undefined);
};<commit_msg>Plugin class - minor code refactoring<commit_after>/**
 * @class Echo.Plugin
 * Foundation class implementing core logic to create plugins and manipulate with them.
 */
Echo.Plugin = function() {};

// static interface
/**
 * @static
 * Function which creates a plugin object using it manifest declaration.
 * 
 * @param {Object} manifest (required) Specifies the plugin interface in the predefined way.
 * @param {String} manifest.name (required) Specifies the Plugin name.
 * @param {Object} [manifest.config] Specifies the configuration data with the ability to define default values.
 * @param {Object} [manifest.labels] Specifies the list of language labels used in the particular plugin UI.
 * @param {Object} [manifest.events] Specifies the list of external events used by plugin.
 * @param {Object} [manifest.methods] Specifies the list of plugin methods.
 * @param {Object} [manifest.renderers] Specifies the list of plugin renderers.
 * @param {Object} [manifest.templates] Specifies the list of plugin templates
 * @param {Function} [manifest.init] Function called during plugin initialization.
 * @param {String} [manifest.css] Specifies the CSS rules for the plugin.
 * @return {Object} generated plugin class
 */
Echo.Plugin.create = function(manifest) {
	var plugin = Echo.Plugin.getClass(manifest.name, manifest.component.name);

	// prevent multiple re-definitions
	if (plugin) return plugin;

	var constructor = function(config) {
		if (!config || !config.component) return;
		var self = this;
		this.name = manifest.name;
		this.component = config.component;
		this.cssClass = this.component.get("cssPrefix") + "plugin-" + manifest.name;
		this.cssPrefix = this.cssClass + "-";

		// define extra css class for the control target
		this.component.config.get("target").addClass(this.cssClass);

		this._init(["config"]);
	};
	constructor.manifest = manifest;
	constructor.dependencies = manifest.dependencies;

	Echo.Utils.inherit(constructor, Echo.Plugin);

	// copy destroy method to the list of methods
	if (manifest.destroy) {
		manifest.methods.destroy = manifest.destroy;
	}

	if (manifest.methods) {
		$.extend(constructor.prototype, manifest.methods);
	}
	Echo.Utils.setNestedValue(
		window,
		Echo.Plugin._getClassName(manifest.name, manifest.component.name),
		constructor
	);
	return constructor;
};

/**
 * @static
 * Method returning common manifest structure.
 * @param {String} name (required) Specifies plugin name.
 * @param {String} component (required) Specifies component name to be extended.
 * @return {Object} Basic plugin manifest declaration.
 */
Echo.Plugin.manifest = function(name, component) {
	return {
		"name": name,
		"component": {
			"name": component,
			"renderers": {}
		},
		"config": {},
		"labels": {},
		"events": {},
		"methods": {},
		"renderers": {},
		"templates": {},
		"dependencies": [],
		"enabled": function() { return true; },
		"init": function(){},
		"destroy": undefined
	};
};

/**
 * @static
 * Checks if plugin is already defined.
 * @param {Object} manifest (required) Plugin manifest.
 * @return {Boolean}
 */
Echo.Plugin.isDefined = function(manifest) {
	return !!Echo.Plugin.getClass(manifest.name, manifest.component.name);
};

/**
 * @static
 * Returns the corresponding plugin by its name and parent component name.
 * @param {String} name {required} Plugin name.
 * @param {String} component {required} Extended component name.
 * @return {Object} Plugin class.
 */
Echo.Plugin.getClass = function(name, component) {
	return Echo.Utils.getNestedValue(window, Echo.Plugin._getClassName(name, component));
};

/**
 *
 * @method
 * Initializes the plugin.
 */
Echo.Plugin.prototype.init = function() {
	this._init([
		"css",
		"events",
		"subscriptions",
		"labels",
		"renderers",
		"dom",
		"launcher"
	]);
};

/**
 *
 * @method
 * Checks if the plugin is enabled.
 */
Echo.Plugin.prototype.enabled = function() {
	if (typeof this._enabled === "undefined") {
		var enabled = this.config.get("enabled", true);
		switch ($.type(enabled)) {
			case "string":
				enabled = enabled === "true";
				break;
			case "function":
				enabled = enabled.call(this);
				break;
		}
		this._enabled = enabled && !!this._manifest("enabled").call(this);
	}
	return this._enabled;
};

/**
 * @method
 * @inheritdoc Echo.Control#set
 */
Echo.Plugin.prototype.set = function(key, value) {
	Echo.Utils.setNestedValue(this, key, value);
};

/**
 * @method
 * @inheritdoc Echo.Control#get
 */
Echo.Plugin.prototype.get = function(key, defaults) {
	return Echo.Utils.getNestedValue(this, key, defaults);
};

/**
 * @method
 * @inheritdoc Echo.Control#remove
 */
Echo.Plugin.prototype.remove = function(key) {
	this.set(key, undefined);
};
{'fraction_non_alphanumeric': 0.14467139379828553, 'fraction_numerical': 0.0, 'mean_word_length': 4.223880597014926, 'pattern_counts': {'":': 30, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5673276', 'n_tokens_mistral': 2974, 'n_tokens_neox': 2777, 'n_words': 808}