<commit_before>/* global Class, cloneObject, Loader, MMSocket, nunjucks, Translator */

/* Magic Mirror
 * Module Blueprint.
 * @typedef {Object} Module
 *
 * By <NAME> https://michaelteeuw.nl
 * MIT Licensed.
 *
 */
var Module = Class.extend({
	/*********************************************************
	 * All methods (and properties) below can be subclassed. *
	 *********************************************************/

	// Set the minimum MagicMirror module version for this module.
	requiresVersion: "2.0.0",

	// Module config defaults.
	defaults: {},

	// Timer reference used for showHide animation callbacks.
	showHideTimer: null,

	// Array to store lockStrings. These strings are used to lock
	// visibility when hiding and showing module.
	lockStrings: [],

	// Storage of the nunjuck Environment,
	// This should not be referenced directly.
	// Use the nunjucksEnvironment() to get it.
	_nunjucksEnvironment: null,

	/**
	 * Called when the module is instantiated.
	 */
	init: function () {
		//Log.log(this.defaults);
	},

	/**
	 * Called when the module is started.
	 */
	start: function () {
		Log.info("Starting module: " + this.name);
	},

	/**
	 * Returns a list of scripts the module requires to be loaded.
	 *
	 * @returns {string[]} An array with filenames.
	 */
	getScripts: function () {
		return [];
	},

	/**
	 * Returns a list of stylesheets the module requires to be loaded.
	 *
	 * @returns {string[]} An array with filenames.
	 */
	getStyles: function () {
		return [];
	},

	/**
	 * Returns a map of translation files the module requires to be loaded.
	 *
	 * return Map<String, String> -
	 *
	 * @returns {*} A map with langKeys and filenames.
	 */
	getTranslations: function () {
		return false;
	},

	/**
	 * Generates the dom which needs to be displayed. This method is called by the Magic Mirror core.
	 * This method can to be subclassed if the module wants to display info on the mirror.
	 * Alternatively, the getTemplate method could be subclassed.
	 *
	 * @returns {HTMLElement|Promise} The dom or a promise with the dom to display.
	 */
	getDom: function () {
		var self = this;
		return new Promise(function (resolve) {
			var div = document.createElement("div");
			var template = self.getTemplate();
			var templateData = self.getTemplateData();

			// Check to see if we need to render a template string or a file.
			if (/^.*((\.html)|(\.njk))$/.test(template)) {
				// the template is a filename
				self.nunjucksEnvironment().render(template, templateData, function (err, res) {
					if (err) {
						Log.error(err);
					}

					div.innerHTML = res;

					resolve(div);
				});
			} else {
				// the template is a template string.
				div.innerHTML = self.nunjucksEnvironment().renderString(template, templateData);

				resolve(div);
			}
		});
	},

	/**
	 * Generates the header string which needs to be displayed if a user has a header configured for this module.
	 * This method is called by the Magic Mirror core, but only if the user has configured a default header for the module.
	 * This method needs to be subclassed if the module wants to display modified headers on the mirror.
	 *
	 * @returns {string} The header to display above the header.
	 */
	getHeader: function () {
		return this.data.header;
	},

	/**
	 * Returns the template for the module which is used by the default getDom implementation.
	 * This method needs to be subclassed if the module wants to use a template.
	 * It can either return a template sting, or a template filename.
	 * If the string ends with '.html' it's considered a file from within the module's folder.
	 *
	 * @returns {string} The template string of filename.
	 */
	getTemplate: function () {
		return '<div class="normal">' + this.name + '</div><div class="small dimmed">' + this.identifier + "</div>";
	},

	/**
	 * Returns the data to be used in the template.
	 * This method needs to be subclassed if the module wants to use a custom data.
	 *
	 * @returns {object} The data for the template
	 */
	getTemplateData: function () {
		return {};
	},

	/**
	 * Called by the Magic Mirror core when a notification arrives.
	 *
	 * @param {string} notification The identifier of the notification.
	 * @param {*} payload The payload of the notification.
	 * @param {Module} sender The module that sent the notification.
	 */
	notificationReceived: function (notification, payload, sender) {
		if (sender) {
			// Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
		} else {
			// Log.log(this.name + " received a system notification: " + notification);
		}
	},

	/**
	 * Returns the nunjucks environment for the current module.
	 * The environment is checked in the _nunjucksEnvironment instance variable.
	 *
	 * @returns {object} The Nunjucks Environment
	 */
	nunjucksEnvironment: function () {
		if (this._nunjucksEnvironment !== null) {
			return this._nunjucksEnvironment;
		}

		var self = this;

		this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), { async: true }), {
			trimBlocks: true,
			lstripBlocks: true
		});

		this._nunjucksEnvironment.addFilter("translate", function (str, variables) {
			return self.translate(str, variables);
		});

		return this._nunjucksEnvironment;
	},
<commit_msg>Marked all translated strings as safe before passing them to the nunjuck template<commit_after>/* global Class, cloneObject, Loader, MMSocket, nunjucks, Translator */

/* Magic Mirror
 * Module Blueprint.
 * @typedef {Object} Module
 *
 * By <NAME> https://michaelteeuw.nl
 * MIT Licensed.
 *
 */
var Module = Class.extend({
	/*********************************************************
	 * All methods (and properties) below can be subclassed. *
	 *********************************************************/

	// Set the minimum MagicMirror module version for this module.
	requiresVersion: "2.0.0",

	// Module config defaults.
	defaults: {},

	// Timer reference used for showHide animation callbacks.
	showHideTimer: null,

	// Array to store lockStrings. These strings are used to lock
	// visibility when hiding and showing module.
	lockStrings: [],

	// Storage of the nunjuck Environment,
	// This should not be referenced directly.
	// Use the nunjucksEnvironment() to get it.
	_nunjucksEnvironment: null,

	/**
	 * Called when the module is instantiated.
	 */
	init: function () {
		//Log.log(this.defaults);
	},

	/**
	 * Called when the module is started.
	 */
	start: function () {
		Log.info("Starting module: " + this.name);
	},

	/**
	 * Returns a list of scripts the module requires to be loaded.
	 *
	 * @returns {string[]} An array with filenames.
	 */
	getScripts: function () {
		return [];
	},

	/**
	 * Returns a list of stylesheets the module requires to be loaded.
	 *
	 * @returns {string[]} An array with filenames.
	 */
	getStyles: function () {
		return [];
	},

	/**
	 * Returns a map of translation files the module requires to be loaded.
	 *
	 * return Map<String, String> -
	 *
	 * @returns {*} A map with langKeys and filenames.
	 */
	getTranslations: function () {
		return false;
	},

	/**
	 * Generates the dom which needs to be displayed. This method is called by the Magic Mirror core.
	 * This method can to be subclassed if the module wants to display info on the mirror.
	 * Alternatively, the getTemplate method could be subclassed.
	 *
	 * @returns {HTMLElement|Promise} The dom or a promise with the dom to display.
	 */
	getDom: function () {
		var self = this;
		return new Promise(function (resolve) {
			var div = document.createElement("div");
			var template = self.getTemplate();
			var templateData = self.getTemplateData();

			// Check to see if we need to render a template string or a file.
			if (/^.*((\.html)|(\.njk))$/.test(template)) {
				// the template is a filename
				self.nunjucksEnvironment().render(template, templateData, function (err, res) {
					if (err) {
						Log.error(err);
					}

					div.innerHTML = res;

					resolve(div);
				});
			} else {
				// the template is a template string.
				div.innerHTML = self.nunjucksEnvironment().renderString(template, templateData);

				resolve(div);
			}
		});
	},

	/**
	 * Generates the header string which needs to be displayed if a user has a header configured for this module.
	 * This method is called by the Magic Mirror core, but only if the user has configured a default header for the module.
	 * This method needs to be subclassed if the module wants to display modified headers on the mirror.
	 *
	 * @returns {string} The header to display above the header.
	 */
	getHeader: function () {
		return this.data.header;
	},

	/**
	 * Returns the template for the module which is used by the default getDom implementation.
	 * This method needs to be subclassed if the module wants to use a template.
	 * It can either return a template sting, or a template filename.
	 * If the string ends with '.html' it's considered a file from within the module's folder.
	 *
	 * @returns {string} The template string of filename.
	 */
	getTemplate: function () {
		return '<div class="normal">' + this.name + '</div><div class="small dimmed">' + this.identifier + "</div>";
	},

	/**
	 * Returns the data to be used in the template.
	 * This method needs to be subclassed if the module wants to use a custom data.
	 *
	 * @returns {object} The data for the template
	 */
	getTemplateData: function () {
		return {};
	},

	/**
	 * Called by the Magic Mirror core when a notification arrives.
	 *
	 * @param {string} notification The identifier of the notification.
	 * @param {*} payload The payload of the notification.
	 * @param {Module} sender The module that sent the notification.
	 */
	notificationReceived: function (notification, payload, sender) {
		if (sender) {
			// Log.log(this.name + " received a module notification: " + notification + " from sender: " + sender.name);
		} else {
			// Log.log(this.name + " received a system notification: " + notification);
		}
	},

	/**
	 * Returns the nunjucks environment for the current module.
	 * The environment is checked in the _nunjucksEnvironment instance variable.
	 *
	 * @returns {object} The Nunjucks Environment
	 */
	nunjucksEnvironment: function () {
		if (this._nunjucksEnvironment !== null) {
			return this._nunjucksEnvironment;
		}

		var self = this;

		this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), { async: true }), {
			trimBlocks: true,
			lstripBlocks: true
		});

		this._nunjucksEnvironment.addFilter("translate", function (str, variables) {
			return nunjucks.runtime.markSafe(self.translate(str, variables));
		});

		return this._nunjucksEnvironment;
	},

{'fraction_non_alphanumeric': 0.13110467830796527, 'fraction_numerical': 0.0005602764030254926, 'mean_word_length': 3.341305229023105, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '1913743', 'n_tokens_mistral': 3333, 'n_tokens_neox': 2938, 'n_words': 1162}