Demo entry 6784934

ggg

   

Submitted by anonymous on Mar 11, 2019 at 21:35
Language: HTML. Code size: 2.0 kB.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <script>
      var templatefx_url = '/api/generate';
      var datatemplate = {};

      function multiline(f) {
        return f.toString().replace(/(?:^.+[\r\n]+|.+$)/g, '');
      }

      datatemplate.data = window.btoa(multiline(function() { /*
A, B, C
1, 2, 3
4, 5, 6
      */ }));

      datatemplate.template = window.btoa(multiline(function() { /*
A is <<A>>
B is <<B>>
C is <<C>>
      */ }));

      datatemplate.snippets = {
        '~FILTER': window.btoa(multiline(function() { /*
A == 1
        */ }))
      };

      var xHR = new XMLHttpRequest();
      xHR.open("POST", templatefx_url, true);
      xHR.onload = function() {
        if (this.status === 200) {
          try {
            var obj = JSON.parse(xHR.responseText);
            if (obj.status === 'ok') {
              if (obj.console.length > 0) {
                console.log(window.atob(obj.console));
              }
              document.write('<pre>');
              for (var i = 0, len = obj.outputs.length; i < len; i++) {
                document.write('Output ' + obj.outputs[i].group + '<br />');
                document.write(window.atob(obj.outputs[i].value) + '<br /><br />');
              }
              document.write('</pre>');
            }
            else {
              document.write('TEMPLATEFX ERROR ' + obj.error.code + ': ' + obj.error.message);
            }
          }
          catch (e) {
            document.write('ERROR: ' + e);
          }
        }
        else {
          document.write('HTTP ERROR ' + this.status + ': ' + this.statusText);
        }
      };

      xHR.onerror = function() {
        document.write('ERROR: XMLHttpRequest.onError()');
      };

      xHR.setRequestHeader("Content-Type", "application/json");
      xHR.send(JSON.stringify(datatemplate));
    </script>
  </head>
</html>

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).