git @ Cat's Eye Technologies Lexeduct / 255235e
Fix bug, refactor, improve; transformers can be composed in UI! Chris Pressey 6 years ago
3 changed file(s) with 17 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1616 <script>
1717 "use strict";
1818
19 var compose = function(g, f) {
20 return function(str, data) {
21 str = f(str, data);
22 return g(str, data);
23 };
24 };
25
1926 var container, input, output, processButton, tranformersPanel;
2027
2128 container = document.getElementById('container');
2734 transformersPanel.style.verticalAlign = "top";
2835
2936 var transformerNames = [["identity", "---"]];
30 for (var key in makeTransformer) {
31 if (key !== 'identity' && makeTransformer.hasOwnProperty(key)) {
37 for (var key in transformer) {
38 if (key !== 'identity' && transformer.hasOwnProperty(key)) {
3239 transformerNames.push([key, key]);
3340 }
3441 }
4754 }
4855
4956 processButton = yoob.makeButton(transformersPanel, "Process", function() {
50 var z = "";
57 var t = transformer['identity'].makeTransformer({});
5158 for (var i = 0; i < transformerSelects.length; i++) {
5259 var select = transformerSelects[i];
53 z += select.options[select.selectedIndex].value +','
60 var transformerName = select.options[select.selectedIndex].value;
61 var t2 = transformer[transformerName].makeTransformer({chars: 'a'});
62 t = compose(t2, t);
5463 }
55 alert(z);
56 var t = makeTransformer['upper']({});
5764 output.value = t(input.value);
5865 });
5966
66 }
77
88 write("module = {};");
9 write("makeTransformer = {};");
9 write("transformer = {};");
1010 var dirname = 'transformers';
1111 var files = fs.readdirSync(dirname);
1212 for (var i = 0; i < files.length; i++) {
1414 var transformerName = filename.split('.js')[0];
1515 var text = fs.readFileSync(dirname + '/' + filename);
1616 write(text);
17 write("makeTransformer['" + transformerName + "'] = module.exports.makeTransformer;");
17 write("transformer['" + transformerName + "'] = module.exports;");
1818 }
22 return function(str, state) {
33 var s = "";
44 for (var i = 0; i < str.length; i++) {
5 if (cfg.chars.indexOf(str.charAt(i)) === -1) {
5 var c = str.charAt(i);
6 if (cfg.chars.indexOf(c) === -1) {
67 s += c;
78 }
89 }