Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed $vars stuff, updated tests

  • Loading branch information...
commit 929c4712bd2709e2b314e808f764bbc6482e1d0e 1 parent e6d4811
James Halliday authored
Showing with 10 additions and 65 deletions.
  1. +1 −48 jadeify.js
  2. +7 −15 test/vars.js
  3. +2 −2 test/vars/msg.jade
49 jadeify.js
View
@@ -20,52 +20,5 @@ module.exports = function (file, vars, opts) {
});
opts.locals.$ = $;
- var evars = {};
- var container = null;
- var defineQueue = [];
-
- var $var = opts.locals.$var = function (key, value) {
- if (arguments.length === 1) value = vars[key];
-
- var r = Math.floor(Math.random() * Math.pow(2,32)).toString(16);
- var id = 'jadeify_' + r;
-
- var elem = $('<div>')
- .css('display', 'inline')
- .attr('id', id)
- ;
-
- if (value instanceof $ || value instanceof window.HTMLElement
- || typeof value === 'string') {
- elem.append(value);
- }
- else {
- elem.append(String(value));
- }
-
- var fn = function () {
- Object.defineProperty(container.vars, key, {
- set : function (x) {
- value = x;
- $('#' + id).empty().append(value);
- },
- get : function () { return value },
- });
- };
-
- if (container) fn()
- else defineQueue.push(fn)
-
- return elem[0].outerHTML;
- };
-
- Object.keys(vars).forEach(function (key) {
- opts.locals['$' + key] = $var(key);
- });
-
- container = $(jade.render(views[file], opts));
- container.vars = {};
- defineQueue.forEach(function (fn) { fn() });
-
- return container;
+ return $(jade.render(views[file], opts));
};
22 test/vars.js
View
@@ -50,7 +50,7 @@ exports.vars = function () {
assert.ok(msg instanceof $);
assert.equal(
- $('#messages .msg .title div').text(),
+ $('#messages .msg .title').text(),
'oh hello'
);
@@ -59,32 +59,24 @@ exports.vars = function () {
'nice night for a test'
);
- msg.vars.title = 'BREAKING NEWS';
+ msg.find('.title').text('BREAKING NEWS');
assert.equal(
- $('#messages .msg .title div').text(),
+ $('#messages .msg .title').text(),
'BREAKING NEWS'
);
- // body doesn't use the $ in the template so it doesn't get
- // modified...
- msg.vars.body = '...';
- assert.equal(
- $('#messages .msg .body').text(),
- 'nice night for a test'
- );
-
// expression test with calling $var()
- assert.equal($('#messages .msg .exp div').text(), '555');
- msg.vars.x = 999;
- assert.equal($('#messages .msg .exp div').text(), '999');
+ assert.equal($('#messages .msg .exp').text(), '555');
+ msg.find('.exp').text(999);
+ assert.equal($('#messages .msg .exp').text(), '999');
c.require('jadeify')('msg.jade', {
title : $('<b>').text('ahoy!'),
body : '...',
}).appendTo($('#messages'));
- var b = $('#messages .msg .title div b');
+ var b = $('#messages .msg .title b');
assert.ok(b[0]);
assert.equal(b.text(), 'ahoy!');
});
4 test/vars/msg.jade
View
@@ -1,4 +1,4 @@
div.msg
- div.title !{$title}
+ div.title !{title}
div.body #{body}
- div.exp !{$var('x', 111 * 5)}
+ div.exp #{111 * 5}
Please sign in to comment.
Something went wrong with that request. Please try again.