Commits

Rune Halvorsen committed 80b64df

Removed zen stuff. Sadly, breaks tests until they are rewritten

Comments (0)

Files changed (3)

     /**
      * Method: append
      *
-     * Append an element, an Unbose object, a template or a zen
-     * string. Append adds the element after the last child element.
+     * Append an element, an Unbose object or a template.
+     * Append adds the element after the last child element.
      * append(thing) is a cleaner shorthand for insert(thing, true)
      *
      * Note that when appending an element to several elements, event
     /**
      * Method: insert
      *
-     * Insert an element, an Unbose object, a template or a zen
-     * string. By default, add it as the first child of the parent. If the
+     * Insert an element, an Unbose object or a template.
+     * By default, add it as the first child of the parent. If the
      * append argument is true, the element is appended as the last child
      * element instead.
      *
                 this._insertElem(e, append);
             }, this);
         }
-        else if (typeof thing === "string") {
-            return this._insertElem(eleFromTpl(tplFromZen(thing)), append);
-        }
         else {
             return this;
         }
 Unbose.eleFromTpl = eleFromTpl;
 
 /**
- * Method: Unbose.tplFromZen
- *
- * Converts a template array to an element (NOT to an unbose object atm).
- */
-function tplFromZen(zen) {
-    return parse_zencode(zen);
-
-    // Here's a whole bunch of private functions for doing the actual parsing.
-    // fimxe: do whitespace cleanup at first instead of inside parser?
-
-    // Main parsing entrypoint
-    function parse_zencode(str) {
-        var chars = str.replace("\n").split("");
-        var ret = [];
-        var n = 10;
-        while (chars.length && --n) {
-            ret = ret.concat((parse_expr(chars)));
-        }
-        return ret;
-    }
-
-    // Expression is top level zen element. tag or parens
-    function parse_expr(chars) {
-        consume_ws(chars);
-        var ret;
-        if (chars[0] == "(") {
-            chars.shift();
-            ret = parse_expr(chars);
-            chars.shift(); // FIXME: Make sure it's ")"
-        }
-        else {
-            ret = parse_tag(chars);
-        }
-
-        consume_ws(chars);
-        var multiplier = get_multiplier(chars);
-        consume_ws(chars);
-        var siblings = parse_siblings(chars);
-        consume_ws(chars);
-        var children = parse_children(chars);
-
-        if (ret.length == 2 && children.length) { // a set of siblings can't have children
-            ret.push(children);
-        }
-
-        while (multiplier--) {
-            siblings.unshift(ret);
-        }
-
-        return siblings.length ? siblings : ret;
-    }
-
-    // Parses a tag, obviously..
-    function parse_tag(chars) {
-        var name = consume_name(chars);
-        var props = parse_props(chars);
-        var current = [name, props];
-        return current;
-    }
-
-    // Consume and return the multiplier if there is one
-    function get_multiplier(chars) {
-        var charsNum = "";
-        if (chars.length && chars[0] == "*") {
-            chars.shift();
-        }
-
-        while (chars.length && chars[0].match(/\d/)) {
-            charsNum += chars.shift();
-        }
-        return parseInt(charsNum, 10) || 1;
-    }
-
-    // Parse siblings
-    function parse_siblings(chars) {
-        var ret = [];
-        while (chars.length && chars[0] == "+") {
-            chars.shift();
-            ret.push(parse_expr(chars));
-        }
-        return ret;
-    }
-
-    // Parse children
-    function parse_children(chars) {
-        var ret = [];
-        if (chars.length && chars[0] == ">") {
-            chars.shift();
-            ret = parse_expr(chars);
-        }
-        return ret;
-    }
-
-    /**
-     * Consume and return anything alphanumeric, a-z,0-9
-     */
-    function consume_name(chars) {
-        var s = "";
-        while (chars.length && chars[0].match(/[a-zA-Z0-9-]/)) {
-            s += chars.shift();
-        }
-        return s;
-    }
-
-    /**
-     * Class names and IDs
-     */
-    function consume_class_or_id(chars) {
-        var s = "";
-        while (chars.length && chars[0].match(/[a-zA-Z0-9-_]/)) {
-            s += chars.shift();
-        }
-        return s;
-    }
-
-    /**
-     * Property values
-     */
-    function consume_value(chars) {
-        var s = "";
-        while (chars.length && chars[0].match(/[a-zA-Z0-9-_#\.\/]/)) {
-            s += chars.shift();
-        }
-        return s;
-    }
-
-    /**
-     * White space
-     */
-    function consume_ws(chars) {
-        var s = "";
-        while (chars.length && chars[0].match(/\s/)) {
-            s += chars.shift();
-        }
-        return s;
-    }
-
-    // consume IDs, classnames and properties
-    function parse_props(chars) {
-        var props = {};
-
-        while (chars.length) {
-            var chr = chars.shift();
-            if (chr == ".") {
-                var className = consume_class_or_id(chars);
-                props["class"] = props["class"] ?
-                    props["class"] + " " + className :
-                    className;
-            }
-            else if (chr == "#") {
-                var id = consume_class_or_id(chars);
-                props["id"] = id;
-            }
-            else if (chr == " ") {
-                var name = consume_name(chars);
-                if (!name) { // no valid name found
-                    break; // presumably whitespace in zen for readability.
-                }
-
-                chars.shift(); // FIXME; make sure is always "="
-                var value = consume_value(chars);
-                props[name] = value;
-            }
-            else {
-                chars.unshift(chr);
-                break;
-            }
-        }
-        return props;
-    }
-};
-Unbose.tplFromZen = tplFromZen;
-
-/**
- * Method: Unbose.eleFromZen
- *
- * Create an HTML element from a zencode string.
- *
- * Parameters:
- *
- *   zen - the string of zencode
- *
- * Returns:
- *
- *   HTMLElement
- *
- * See also:
- *
- *   <fromZen>
- *
- */
-function eleFromZen(zen) {
-    return Unbose.eleFromTpl(Unbose.tplFromZen(zen));
-};
-Unbose.eleFromZen = eleFromZen;
-
-/**
- * Method: Unbose.fromZen
- *
- * Create an Unbose object from a zencode string.
- *
- * Parameters:
- *
- *   zen - the string of zencode
- *
- * Returns:
- *
- *   Unbose element of zencode
- *
- * See also:
- *
- *   <eleFromZen>
- *
- */
-function fromZen(zen) {
-    return new Unbose(Unbose.eleFromZen(zen));
-};
-Unbose.fromZen = fromZen;
-
-/**
  * Group: Static helper methods
  *
  * Various helper methods

tests/qunit/unbose.tests.html

 <script src="../dom.js"></script>
 <script src="../style.js"></script>
 <script src="../events.js"></script>
-<script src="../zen.js"></script>
 <script src="../tools.js"></script>
 <h1 id="qunit-header">unbose tests</h1>
 <h2 id="qunit-banner"></h2>

tests/zen.js

-// The tests are copied from
-// http://github.com/chrisdone/zencoding/blob/master/zencoding-mode.el
-
-
-// Tests pass in latest opera and latest chrome on linux.
-// Does not pass in firefox but that's due to the order of
-// properties on the string returned from innerHTML. Opera
-// and chrome uses insert order, firefox alphabetically it seems.
-// Not a bug, just an implementation artifact. In other words, the
-// emitted code should be correct in all three browsers.
-
-
-// Helper function for making an html string we can compare with.
-function zen(s) {
-                 var div = Unbose(document.createElement("div"));
-                 div.append(s);
-                 return div.elem(0).innerHTML.toLowerCase();
-                 }
-
-module("Zencode");
-
-test("Basic tests", function() {
-    equals(zen("a"), "<a></a>");
-    equals(zen("a.b"), '<a class="b"></a>');
-    equals(zen("a#q"), '<a id="q"></a>');
-    equals(zen("a#q.x"), '<a id="q" class="x"></a>');
-    equals(zen("a#q.x.y.z"), '<a id="q" class="x y z"></a>');
-    equals(zen("a.class-with-dash"), '<a class="class-with-dash"></a>');
-    equals(zen("a#id-with-dash"), '<a id="id-with-dash"></a>');
-});
-
-test("Siblings", function() {
-    equals(zen("a+b"), "<a></a><b></b>");
-    equals(zen("a.x+b"), '<a class="x"></a><b></b>');
-    equals(zen("a#q.x+b"), '<a id="q" class="x"></a><b></b>');
-    equals(zen("a#q.x.y.z+b#p.l.m.n"), '<a id="q" class="x y z"></a><b id="p" class="l m n"></b>');
-});
-
-test("Parent > Child", function() {
-    equals(zen("a>b"), "<a><b></b></a>");
-    equals(zen("a>b>c"), "<a><b><c></c></b></a>");
-    equals(zen("a.x>b"), '<a class="x"><b></b></a>');
-    equals(zen("a#q.x>b"), '<a id="q" class="x"><b></b></a>');
-    equals(zen("a#q.x.y.z>b#p.l.m.n"), '<a id="q" class="x y z"><b id="p" class="l m n"></b></a>');
-    equals(zen("a>b+c"), "<a><b></b><c></c></a>");
-    equals(zen("a>b+c>d"), "<a><b></b><c><d></d></c></a>");
-    equals(zen("a>b+c>d+e>f"), "<a><b></b><c><d></d><e><f></f></e></c></a>");
-});
-
-test("Multiplication", function() {
-    equals(zen("a*2"), "<a></a><a></a>");
-    equals(zen("a*2+b*2"), "<a></a><a></a><b></b><b></b>");
-    equals(zen("a*2>b*2"), "<a><b></b><b></b></a><a><b></b><b></b></a>");
-    equals(zen("a>b*2"), "<a><b></b><b></b></a>");
-    equals(zen("a#q.x>b#q.x*2"), '<a id="q" class="x"><b id="q" class="x"></b><b id="q" class="x"></b></a>');
-    equals(zen("a*11"), "<a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a><a></a>");
-});
-
-test("Properties", function() {
-    equals(zen("a x=y"), "<a x=\"y\"></a>");
-    equals(zen("a x=y m=l"), "<a x=\"y\" m=\"l\"></a>");
-    equals(zen("a#foo x=y m=l"), "<a id=\"foo\" x=\"y\" m=\"l\"></a>");
-    equals(zen("a.foo x=y m=l"), "<a class=\"foo\" x=\"y\" m=\"l\"></a>");
-    equals(zen("a#foo.bar.mu x=y m=l"), "<a id=\"foo\" class=\"bar mu\" x=\"y\" m=\"l\"></a>");
-    equals(zen("a x=y+b"), "<a x=\"y\"></a><b></b>");
-    equals(zen("a x=y+b x=y"), "<a x=\"y\"></a><b x=\"y\"></b>");
-    equals(zen("a x=y>b"), "<a x=\"y\"><b></b></a>");
-    equals(zen("a x=y>b x=y"), "<a x=\"y\"><b x=\"y\"></b></a>");
-    equals(zen("a x=y>b x=y+c x=y"), "<a x=\"y\"><b x=\"y\"></b><c x=\"y\"></c></a>");
-    equals(zen("a data-foo=bar"), "<a data-foo=\"bar\"></a>");
-    equals(zen("img src=foo/bar.png"), '<img src="foo/bar.png">');
-});
-
-test("Parenthesis", function() {
-    equals(zen("(a)"), "<a></a>");
-    equals(zen("(a)+(b)"), "<a></a><b></b>");
-    equals(zen("a>(b)"), "<a><b></b></a>");
-    equals(zen("(a>b)>c"), "<a><b></b></a>"); // yes, c is droppeed. group can't have children
-    equals(zen("(a>b)+c"), "<a><b></b></a><c></c>");
-    equals(zen("z+(a>b)+c+k"), "<z></z><a><b></b></a><c></c><k></k>");
-    equals(zen("(a)*2"), "<a></a><a></a>");
-    equals(zen("((a)*2)"), "<a></a><a></a>");
-    equals(zen("(a>b)*2"), "<a><b></b></a><a><b></b></a>");
-    equals(zen("(a+b)*2"), "<a></a><b></b><a></a><b></b>");
-});
-
-test("whitespace in zencode", function() {
-    var ele = Unbose.fromZen("div > div");
-    ok(ele, "Elem generated");
-    equals(ele.length, 1);
-
-    var ele = Unbose.fromZen("div + div");
-    ok(ele, "Elem generated");
-    equals(ele.length, 2);
-
-    var ele = Unbose.fromZen("div +( div )");
-    ok(ele, "Elem generated");
-    equals(ele.length, 2);
-
-    var ele = Unbose.fromZen("div + (div)");
-    ok(ele, "Elem generated");
-    equals(ele.length, 2);
-
-    var ele = Unbose.fromZen("(div) + (div)");
-    ok(ele, "Elem generated");
-    equals(ele.length, 2);
-
-    var ele = Unbose.fromZen(" ( div#asdf.zxcv ) + ( div.foo#meh meh=123) ");
-    ok(ele, "Elem generated");
-    equals(ele.length, 2);
-    equals(ele.nth(1).attr("meh"), 123);
-
-    var ele = Unbose.fromZen("(div\n) \n+\n (\ndiv)");
-    ok(ele, "Elem generated");
-    equals(ele.length, 2);
-});
-