'can viewify an array of renderables': function() { $._reset(); var result = $.viewify('div', {}, [ // html string '<p>Foo</p>', // tag $.tag('h1', {}, 'Bar'), // view new PlaceholderView('Placeholder'), // outlet new Outlet('table', {}, 'Outlet'), // array of the above [ '<p>Foo2</p>', $.tag('h2', {}, 'Bar'), new PlaceholderView('Placeholder2'), new Outlet('table', {}, 'Outlet2'), ] ]), asHtml = $.html(result.render()); assert.equal(typeof result.render, 'function'); assert.ok(result.id); // console.log(asHtml); assert.equal(asHtml, '<div id="3">'+ '<p>Foo</p>'+ '<h1>Bar</h1>'+ '<p id="4">Placeholder</p>'+ '<table id="1">Outlet</table>'+ '<p>Foo2</p>'+ '<h2>Bar</h2>'+ '<p id="5">Placeholder2</p>'+ '<table id="2">Outlet2</table>'+ '</div>') }
'can viewify a tag': function() { $._reset(); var result = $.viewify('div', {}, $.tag('div', { id: 100 }, 'Hello')), asHtml = $.html(result.render()); assert.equal(typeof result.render, 'function'); assert.ok(result.id); // console.log(asHtml); assert.equal(asHtml, '<div id="1"><div id="100">Hello</div></div>') },
'can viewify a string': function() { $._reset(); var result = $.viewify('div', {}, '<p>Foo</p>'), asHtml = $.html(result.render()); assert.equal(typeof result.render, 'function'); assert.ok(result.id); // console.log(asHtml); assert.equal(asHtml, '<div id="1"><p>Foo</p></div>') },
TestView.prototype.render = function() { var self = this; return $.tag('div', [ $.tag('div', function(count) { return 'Clicks: ' + count; }), $.tag('button', { onclick: function() { self.increment(); return false; } }, 'Click me') ]); };
ExampleView.prototype._render = function() { this.id = $.id(); return $.tag('p', { id: this.id }, 'Hello world!'); };
assert = require('assert'); var Parser = require('jade').Parser, $ = require('cato').Shim, compiler = require('cato').Jade; var cases = { 'basic': [ [ 'html', ' body', ' h1 Title' ], [ $.tag('html', $.tag('body', $.tag('h1', 'Title'))) ] ], 'attrs-data': [ [ "foo(data-user=user)", "foo(data-items=[1,2,3])", "foo(data-username='******')" ], [ $.tag('foo', { 'data-user': '******' }, ''), $.tag('foo', { 'data-items': '[1,2,3]'}, ''), $.tag('foo', { 'data-username': '******'}, '') ] ],