Debian Codegraph @

codegen/index.html

raw
1 <html>
2 <head>
3 <title>
4 Codegen
5 </title>
6 <style>
7 body {
8 width: 800px;
9 margin: auto;
10 }
11 textarea {
12 width: 100%;
13 min-height: 100px;
14 font-family: Courier;
15 }
16 </style>
17 </head>
18 <body>
19
20 <h2>
21 Template
22 </h2>
23 <p>
24 Use <code>{x}</code> as a placeholder for each argument.
25 </p>
26 <textarea id="template"></textarea>
27
28 <h2>
29 Arguments (comma separated)
30 </h2>
31 <p>
32 One block per line
33 </p>
34 <textarea id="args"></textarea>
35
36 <h2>
37 Output
38 </h2>
39 <input id="go" type="button" value="Generate code" />
40
41 <textarea id="output"></textarea>
42
43 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
44 <script>
45
46 $(function(){
47
48 $("#go").click(function(){
49
50 var output = ""
51 var template = $("#template").val()
52 var args = $("#args").val()
53
54 // collect the args
55 var argLines = args.split("\n")
56 for (var line in argLines) {
57
58 var argLine = argLines[line];
59 var thisTemp = template
60
61 // get individual args
62 var args = argLine.split(",")
63
64 for (var argI in args) {
65 var argText = args[argI];
66 var argPlaceholder = "{" + argI + "}";
67
68 while (thisTemp.indexOf(argPlaceholder) > -1) {
69 thisTemp = thisTemp.replace(argPlaceholder, argText);
70 }
71
72 }
73
74 output += thisTemp
75
76 }
77
78 $("#output").val(output);
79
80 });
81
82 });
83
84 </script>
85 </body>
86 </html>