JSFiddle - React, Tailwind, and code Playground

by Andy Edinborough

HTML

<div class="example">
    <pre class="template">@model.value_test this @@ is a test! @*comment*@ @(method_test("@")) @method_test("a") @model.value_test more text @if(model.value_test === 1){ method_test(); @method_test(0); } @(model.value_test) @model.value_test</pre>
    <pre class="model">{ value_test: 1 }</pre>
    <pre class="page">{ method_test: function(a) { return a; } }</pre>
    <pre class="expected">1 this @ is a test!  @ a 1 more text 0 1 1</pre>
</div>

Now at <a href="https://gist.github.com/1771064">https://gist.github.com/1771064</a>

CSS

pre {
    background: #eee;
    margin: 4px 0;
    padding:5px;
    position: relative;
}
pre:before{
    font-family: sans-serif;
    font-size: 10px;
    font-style: italic;
    position: absolute;
    top: 0; right: 0;
    color: #aaa;
}
pre.template { white-space: normal; }
pre.template:before { content: 'Template'; }
pre.model:before { content: 'Model'; }
pre.page:before { content: 'Page'; }
pre.parsed:before { content: 'Parsed'; }
pre.expected:before { content: 'Expected'; }

.result { color: #070; }
.error {
  color: #700;   
}

.example { 
    padding: 5px; 
    margin: 1em;
    border: solid 1px #eee;
}

JavaScript

/*global window */
/*jshint curly: false, evil: true */
var Razor = (function () {
  var Reader = window.Reader = function () {
    'use strict';

    var reader = function (text) {
      this.text = (text || '') + '';
      this.position = -1;
      this.length = this.text.length;
    };

    reader.prototype.read = function (len) {
      var value = this.peek(len);
      this.position = Math.min(this.length, this.position + (len || 1));
      return value;
    };

    reader.prototype.readAll = function () {
      if (this.position >= this.length) return undefined;
      var value = this.text.substr(this.position + 1);
      this.position = this.length;
      return value;
    };

    reader.prototype.peek = function (len) {
      if ((this.position + 1) >= this.length) return undefined;
      return this.text.substr(this.position + 1, len || 1);
    };

    reader.prototype.seek = function (offset, pos) {
      this.position = Math.max(0,
      Math.min(this.length,
        (pos === 0 ? 0 : pos === 2 ? this.length : this.position) +
        (offset || 1)
        )
      );
      return this.position === this.length;
    };

    reader.prototype.readUntil = function (chars) {
      if (typeof chars === 'string') chars = [chars];
      var l, rdr = this, cache = [], len = chars.length, result = { value: '', next: '' };

      function predicate(chr) {
        l = chr.length;
        result.next = cache[l] || (cache[l] = rdr.peek(l));
        return result.next === chr;
      }

      while (true) {
        cache.length = 0;
        if (chars.some(predicate)) {
          this.seek(l);
          return result;
        }

        result.next = this.read();
        if (result.next) {
          result.value += result.next;
        } else break;
      }

      return result;
    };

    return reader;
  } ();

  //Reader Extensions
  var rxValid = /^[a-z0-9\.\(\)\[\]_]+/;
  function last(str) {
    return (str = (str || ''))[str.length - 1] || '';
  }

 ...