git @ Cat's Eye Technologies Lexeduct / b84e8c8
Transformers in UI take parameters; crude version of "live mode". Chris Pressey 7 years ago
2 changed file(s) with 74 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
8383 `state` is an object whose members may be read or written to store ancillary
8484 state. (Doing so will make it an 'impure' pipeline.)
8585
86 In-Browser Version
87 ------------------
88
89 Run `./make.sh` from this directory (or the commands it contains) to generate
90 a Javascript file which contains all the available transformers in a format
91 suitable for loading in an HTML document.
92
93 Open `demo/lexeduct.html` in your browser. It provides a UI for composing
94 these transformers and applying them to text provided in a textarea.
95
8696 Acknowledgements
8797 ----------------
8898
98108 * Allow filters return multiple, or no, strings.
99109 * Many, many other things.
100110
111 ### In-browser UI ###
112
113 * Dynamically allocate the number of transformer-slots.
114 * Provide "insert" and "delete" operations on each transformer-slot.
115 * Display the description for each select transformer, in a tooltip(?)
116 * Create prompts for available params dynamically in each transformer-slot.
117
101118 [Michael Paulukonis]: https://github.com/MichaelPaulukonis/
102119 [TextMunger]: https://github.com/MichaelPaulukonis/text-munger
103120 [GenerativeText Forum]: https://groups.google.com/forum/#!forum/generativetext
3333 transformersPanel.style.display = "inline-block";
3434 transformersPanel.style.verticalAlign = "top";
3535
36 var MAX_TRANSFORMERS = 8; // TODO dynamic
37 var transformerSlots = [];
38
3639 var transformerNames = [["identity", "---"]];
3740 for (var key in transformer) {
3841 if (key !== 'identity' && transformer.hasOwnProperty(key)) {
4043 }
4144 }
4245
43 var MAX_TRANSFORMERS = 8; // TODO dynamic
44 var transformerSelects = [];
46 var parseOptions = function(text) {
47 var args = text.split(' ');
48 var cfg = {};
49 for (var i = 0; i < args.length; i++) {
50 var paramPair = args[i].split('=');
51 if (paramPair.length == 2) {
52 cfg[paramPair[0]] = paramPair[1];
53 } else {
54 // register an error
55 }
56 }
57 return cfg;
58 };
59
60 var process = function() {
61 var t = transformer['identity'].makeTransformer({});
62 for (var i = 0; i < transformerSlots.length; i++) {
63 var select = transformerSlots[i].select;
64 var transformerName = select.options[select.selectedIndex].value;
65 var options = parseOptions(transformerSlots[i].optionsInput.value);
66 var t2 = transformer[transformerName].makeTransformer(options);
67 t = compose(t2, t);
68 }
69 var inLines = input.value.split('\n');
70 var outLines = [];
71 for (var i = 0; i < inLines.length; i++) {
72 outLines.push(t(inLines[i]));
73 }
74 output.value = outLines.join('\n');
75 };
76
77 processButton = yoob.makeButton(transformersPanel, "Process", process);
78
79 var liveMode;
80 yoob.makeCheckbox(transformersPanel, false, "Live mode", function(b) {
81 liveMode = b;
82 });
83 yoob.makeLineBreak(transformersPanel);
4584
4685 for (var i = 0; i < MAX_TRANSFORMERS; i++) {
4786 var select = yoob.makeSelect(
4887 transformersPanel, "Transformer " + (i+1), transformerNames
4988 );
50 transformerSelects.push(select);
89 select.onchange = function(e) {
90 if (liveMode) {
91 process();
92 }
93 };
5194 yoob.makeLineBreak(transformersPanel);
52 yoob.makeTextInput(transformersPanel, 24);
95 var optionsInput = yoob.makeTextInput(transformersPanel, 24);
96 optionsInput.onchange = function(e) {
97 if (liveMode) {
98 process();
99 }
100 };
101 optionsInput.title = "Options";
53102 yoob.makeLineBreak(transformersPanel);
103 transformerSlots.push({
104 select: select,
105 optionsInput: optionsInput
106 });
54107 }
55
56 processButton = yoob.makeButton(transformersPanel, "Process", function() {
57 var t = transformer['identity'].makeTransformer({});
58 for (var i = 0; i < transformerSelects.length; i++) {
59 var select = transformerSelects[i];
60 var transformerName = select.options[select.selectedIndex].value;
61 var t2 = transformer[transformerName].makeTransformer({chars: 'a'});
62 t = compose(t2, t);
63 }
64 output.value = t(input.value);
65 });
66108
67109 output = yoob.makeTextArea(container, 40, 20);
68110 </script>