<commit_before>/**
 * @file Editor/viewer interface
 * @author Scimonster
 * @license {@link LICENSE} (AGPL)
 */
var fs       = require('fs'),
    path     = require('path'),
    extend   = require('extend'),
    put      = require('put-selector'),
    all      = {},
    programs = fs.readdirSync(__dirname);
programs.forEach(function(p) {
	if (fs.statSync(path.join(__dirname,p)).isDirectory()) { // find subdirectories of here
		all[p] = require(path.join(__dirname,p));
	}
});
exports.all = all;

exports.messages = {};
for (var program in all) {
	extend(true, exports.messages, all[program].messages);
}

exports.routes = {};
for (var program in all) {
	exports.routes[program] = all[program].routes;
}

exports.editorsForFile = function(file, showAll) {
	return Object.keys(all).
		filter(function(p){
			return all[p].mimetypes.filter(function(regex){
				if (file instanceof Array) {
					return file.every(function(f){
						return regex.test(f.type);
					});
				}
				return regex.test(file.type);
			}).length && (showAll || !all[p].noShow);
		}).
		map(function(p){
			return {modName: all[p].modName, name: all[p].name, desc: all[p].desc};
		});
};

exports.allEditors = Object.keys(all).map(function(ed){return {modName: all[ed].modName, name: all[ed].name, desc: all[ed].desc}});

exports.generateButtons = function(buttonFunction, file, cb) {
	var _ = require('../text')(require('../lang').code);
	put.defaultTag = 'button';
	buttonFunction(file, function(buttons) {
		cb(buttons.map(function(b){
			if (b instanceof Array) { // a buttonset
				return b.map(function(bsetB){return buttonFromObject(bsetB)});
			}
			return buttonFromObject(b);
		}));
	});
	function buttonFromObject(button) {
		var b = {elem: '', icons: {}};
		if (button.elem.trim()[0] == '<') { // button.elem is an HTML string
			b.elem = button.elem;
		} else {
			if (button.message) {
				b.elem = put(button.elem, _(button.message));
			} else {
				b.elem = put(button.elem);
			}<commit_msg>programs: more Scheme-style programming<commit_after>/**
 * @file Editor/viewer interface
 * @author Scimonster
 * @license {@link LICENSE} (AGPL)
 */
var fs       = require('fs'),
    path     = require('path'),
    extend   = require('extend'),
    put      = require('put-selector'),
    all      = {},
    arr      = [],
    programs = fs.readdirSync(__dirname);
programs.forEach(function(p) {
	if (fs.statSync(path.join(__dirname,p)).isDirectory()) { // find subdirectories of here
		all[p] = require(path.join(__dirname,p));
		arr.push(all[p]);
	}
});
exports.all = all;
exports.arr = arr;

exports.messages = arr.reduce(function(prev, cur){return extend(true, prev, cur.messages)}, {});

exports.routes = arr.reduce(function(prev, cur){
	var a = {};
	a[cur.modName] = cur.routes;
	return extend(true, prev, a);
}, {});

exports.editorsForFile = function(file, showAll) {
	return arr.filter(function(p){
		return p.mimetypes.filter(function(regex){
			if (file instanceof Array) {
				return file.every(function(f){
					return regex.test(f.type);
				});
			}
			return regex.test(file.type);
		}).length && (showAll || !p.noShow);
	}).map(function(p){
		return {modName: p.modName, name: p.name, desc: p.desc};
	});
};

exports.allEditors = arr.map(function(ed){return {modName: ed.modName, name: ed.name, desc: ed.desc}});

exports.generateButtons = function(buttonFunction, file, cb) {
	var _ = require('../text')(require('../lang').code);
	put.defaultTag = 'button';
	buttonFunction(file, function(buttons) {
		cb(buttons.map(function(b){
			if (b instanceof Array) { // a buttonset
				return b.map(function(bsetB){return buttonFromObject(bsetB)});
			}
			return buttonFromObject(b);
		}));
	});
	function buttonFromObject(button) {
		var b = {elem: '', icons: {}};
		if (button.elem.trim()[0] == '<') { // button.elem is an HTML string
			b.elem = button.elem;
		} else {
			if (button.message) {
				b.elem = put(button.elem, _(button.message));
			} else {
				b.elem = put(button.elem);
			}
{'fraction_non_alphanumeric': 0.18682694715752568, 'fraction_numerical': 0.0005008765339343851, 'mean_word_length': 3.760429082240763, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3553146', 'n_tokens_mistral': 1479, 'n_tokens_neox': 1373, 'n_words': 272}