0000: 76 61 72 20 67 6c 6f 62 20 3d 20 72 65 71 75 69 var glob = requi
0010: 72 65 28 27 67 6c 6f 62 27 29 2c 0a 20 20 70 61 re('glob'),. pa
0020: 74 68 20 3d 20 72 65 71 75 69 72 65 28 27 70 61 th = require('pa
0030: 74 68 27 29 2c 0a 20 20 72 69 6f 74 20 3d 20 72 th'),. riot = r
0040: 65 71 75 69 72 65 28 27 2e 2e 2f 2e 2e 2f 2e 2e equire('../../..
0050: 2f 6c 69 62 2f 73 65 72 76 65 72 27 29 2c 0a 20 /lib/server'),.
0060: 20 65 78 70 65 63 74 20 3d 20 72 65 71 75 69 72 expect = requir
0070: 65 28 27 63 68 61 69 27 29 2e 65 78 70 65 63 74 e('chai').expect
0080: 2c 0a 20 20 63 68 65 65 72 69 6f 20 3d 20 72 65 ,. cheerio = re
0090: 71 75 69 72 65 28 27 63 68 65 65 72 69 6f 27 29 quire('cheerio')
00a0: 0a 0a 64 65 73 63 72 69 62 65 28 27 4e 6f 64 65 ..describe('Node
00b0: 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a ', function() {.
00c0: 0a 20 20 2f 2f 20 61 64 64 73 20 63 75 73 74 6f . // adds custo
00d0: 6d 20 72 69 6f 74 20 70 61 72 73 65 72 73 20 75 m riot parsers u
00e0: 73 65 64 20 62 79 20 73 6f 6d 65 20 74 61 67 2f sed by some tag/
00f0: 2a 2e 74 61 67 20 66 69 6c 65 73 0a 20 20 2f 2f *.tag files. //
0100: 20 63 73 73 0a 20 20 72 69 6f 74 2e 70 61 72 73 css. riot.pars
0110: 65 72 73 2e 63 73 73 2e 6d 79 70 61 72 73 65 72 ers.css.myparser
0120: 20 3d 20 66 75 6e 63 74 69 6f 6e 20 28 74 61 67 = function (tag
0130: 2c 20 63 73 73 29 20 7b 0a 20 20 20 20 72 65 74 , css) {. ret
0140: 75 72 6e 20 63 73 73 2e 72 65 70 6c 61 63 65 28 urn css.replace(
0150: 2f 40 74 61 67 2f 2c 20 74 61 67 29 0a 20 20 7d /@tag/, tag). }
0160: 0a 20 20 2f 2f 20 6a 73 0a 20 20 72 69 6f 74 2e . // js. riot.
0170: 70 61 72 73 65 72 73 2e 6a 73 2e 6d 79 70 61 72 parsers.js.mypar
0180: 73 65 72 20 3d 20 66 75 6e 63 74 69 6f 6e 20 28 ser = function (
0190: 6a 73 29 20 7b 0a 20 20 20 20 72 65 74 75 72 6e js) {. return
01a0: 20 6a 73 2e 72 65 70 6c 61 63 65 28 2f 40 76 65 js.replace(/@ve
01b0: 72 73 69 6f 6e 2f 2c 20 27 31 2e 30 2e 30 27 29 rsion/, '1.0.0')
01c0: 0a 20 20 7d 0a 0a 20 20 69 74 28 27 72 65 71 75 . }.. it('requ
01d0: 69 72 65 20 74 61 67 73 27 2c 20 66 75 6e 63 74 ire tags', funct
01e0: 69 6f 6e 28 64 6f 6e 65 29 20 7b 0a 20 20 20 20 ion(done) {.
01f0: 67 6c 6f 62 28 27 2e 2e 2f 2e 2e 2f 74 61 67 2f glob('../../tag/
0200: 2a 2e 74 61 67 27 2c 20 7b 20 63 77 64 3a 20 5f *.tag', { cwd: _
0210: 5f 64 69 72 6e 61 6d 65 20 7d 2c 20 66 75 6e 63 _dirname }, func
0220: 74 69 6f 6e 20 28 65 72 72 2c 20 74 61 67 73 29 tion (err, tags)
0230: 20 7b 0a 20 20 20 20 20 20 65 78 70 65 63 74 28 {. expect(
0240: 65 72 72 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c err).to.be.equal
0250: 28 6e 75 6c 6c 29 0a 20 20 20 20 20 20 74 61 67 (null). tag
0260: 73 2e 66 6f 72 45 61 63 68 28 66 75 6e 63 74 69 s.forEach(functi
0270: 6f 6e 28 74 61 67 29 20 7b 0a 20 20 20 20 20 20 on(tag) {.
0280: 20 20 69 66 20 28 2f 7e 2f 2e 74 65 73 74 28 74 if (/~/.test(t
0290: 61 67 29 29 20 72 65 74 75 72 6e 0a 20 20 20 20 ag)) return.
02a0: 20 20 20 20 65 78 70 65 63 74 28 72 65 71 75 69 expect(requi
02b0: 72 65 28 74 61 67 29 29 2e 74 6f 2e 62 65 2e 6f re(tag)).to.be.o
02c0: 6b 0a 20 20 20 20 20 20 7d 29 0a 20 20 20 20 20 k. }).
02d0: 20 64 6f 6e 65 28 29 0a 20 20 20 20 7d 29 0a 20 done(). }).
02e0: 20 7d 29 0a 0a 20 20 69 74 28 27 72 69 6f 74 2e }).. it('riot.
02f0: 64 65 66 61 75 6c 74 20 73 68 6f 75 6c 64 20 6e default should n
0300: 6f 74 20 62 65 20 65 78 70 6f 72 74 65 64 20 69 ot be exported i
0310: 6e 20 63 6f 6d 6d 6f 6e 6a 73 20 65 6e 76 69 72 n commonjs envir
0320: 6e 6f 6e 6d 65 6e 74 73 27 2c 20 66 75 6e 63 74 nonments', funct
0330: 69 6f 6e 28 29 20 7b 0a 20 20 20 20 65 78 70 65 ion() {. expe
0340: 63 74 28 72 69 6f 74 2e 64 65 66 61 75 6c 74 29 ct(riot.default)
0350: 2e 74 6f 2e 62 65 2e 6e 6f 74 2e 6f 6b 0a 20 20 .to.be.not.ok.
0360: 7d 29 0a 0a 20 20 69 74 28 27 72 65 6e 64 65 72 }).. it('render
0370: 20 74 61 67 3a 20 74 69 6d 65 72 27 2c 20 66 75 tag: timer', fu
0380: 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 76 nction() {. v
0390: 61 72 20 74 6d 72 20 3d 20 72 69 6f 74 2e 72 65 ar tmr = riot.re
03a0: 6e 64 65 72 28 27 74 69 6d 65 72 27 2c 20 7b 20 nder('timer', {
03b0: 73 74 61 72 74 3a 20 34 32 20 7d 29 0a 20 20 20 start: 42 }).
03c0: 20 65 78 70 65 63 74 28 74 6d 72 29 2e 74 6f 2e expect(tmr).to.
03d0: 62 65 2e 65 71 75 61 6c 28 27 3c 74 69 6d 65 72 be.equal('<timer
03e0: 3e 3c 70 3e 53 65 63 6f 6e 64 73 20 45 6c 61 70 ><p>Seconds Elap
03f0: 73 65 64 3a 20 34 32 3c 2f 70 3e 3c 2f 74 69 6d sed: 42</p></tim
0400: 65 72 3e 27 29 0a 20 20 7d 29 0a 0a 20 20 69 74 er>'). }).. it
0410: 28 27 72 65 6e 64 65 72 20 74 61 67 3a 20 69 66 ('render tag: if
0420: 2d 74 65 73 74 27 2c 20 66 75 6e 63 74 69 6f 6e -test', function
0430: 28 29 20 7b 0a 20 20 20 20 76 61 72 20 69 66 74 () {. var ift
0440: 20 3d 20 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 = riot.render('
0450: 69 66 2d 74 65 73 74 27 29 0a 20 20 20 20 76 61 if-test'). va
0460: 72 20 24 20 3d 20 63 68 65 65 72 69 6f 2e 6c 6f r $ = cheerio.lo
0470: 61 64 28 69 66 74 29 0a 20 20 20 20 76 61 72 20 ad(ift). var
0480: 65 6c 73 20 3d 20 24 28 27 69 66 2d 63 68 69 6c els = $('if-chil
0490: 64 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65 d'). expect(e
04a0: 6c 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 ls.length).to.be
04b0: 2e 65 71 75 61 6c 28 31 29 0a 20 20 20 20 65 78 .equal(1). ex
04c0: 70 65 63 74 28 65 6c 73 2e 66 69 72 73 74 28 29 pect(els.first()
04d0: 2e 61 74 74 72 28 27 73 74 79 6c 65 27 29 29 2e .attr('style')).
04e0: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 64 69 73 to.be.equal('dis
04f0: 70 6c 61 79 3a 20 6e 6f 6e 65 3b 27 29 0a 20 20 play: none;').
0500: 7d 29 0a 0a 20 20 69 74 28 27 72 65 6e 64 65 72 }).. it('render
0510: 20 74 61 67 3a 20 61 74 74 72 2d 74 65 73 74 27 tag: attr-test'
0520: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 , function() {.
0530: 20 20 20 76 61 72 20 63 6f 6e 74 65 6e 74 20 3d var content =
0540: 20 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 61 74 riot.render('at
0550: 74 72 2d 74 65 73 74 27 2c 20 7b 20 72 65 64 3a tr-test', { red:
0560: 20 74 72 75 65 20 7d 29 0a 20 20 20 20 65 78 70 true }). exp
0570: 65 63 74 28 63 6f 6e 74 65 6e 74 29 2e 74 6f 2e ect(content).to.
0580: 62 65 2e 65 71 75 61 6c 28 27 3c 61 74 74 72 2d be.equal('<attr-
0590: 74 65 73 74 3e 3c 69 6e 70 75 74 20 74 79 70 65 test><input type
05a0: 3d 22 63 68 65 63 6b 62 6f 78 22 20 63 6c 61 73 ="checkbox" clas
05b0: 73 3d 22 72 65 64 22 3e 20 3c 2f 61 74 74 72 2d s="red"> </attr-
05c0: 74 65 73 74 3e 27 29 0a 0a 20 20 20 20 63 6f 6e test>').. con
05d0: 74 65 6e 74 20 3d 20 72 69 6f 74 2e 72 65 6e 64 tent = riot.rend
05e0: 65 72 28 27 61 74 74 72 2d 74 65 73 74 27 2c 20 er('attr-test',
05f0: 7b 20 69 73 43 68 65 63 6b 65 64 3a 20 74 72 75 { isChecked: tru
0600: 65 2c 20 69 6e 63 6c 75 64 65 54 61 62 6c 65 3a e, includeTable:
0610: 20 74 72 75 65 20 7d 29 0a 20 20 20 20 65 78 70 true }). exp
0620: 65 63 74 28 63 6f 6e 74 65 6e 74 29 2e 74 6f 2e ect(content).to.
0630: 62 65 2e 65 71 75 61 6c 28 27 3c 61 74 74 72 2d be.equal('<attr-
0640: 74 65 73 74 3e 3c 69 6e 70 75 74 20 74 79 70 65 test><input type
0650: 3d 22 63 68 65 63 6b 62 6f 78 22 20 63 68 65 63 ="checkbox" chec
0660: 6b 65 64 3d 22 63 68 65 63 6b 65 64 22 3e 20 3c ked="checked"> <
0670: 74 61 62 6c 65 3e 3c 2f 74 61 62 6c 65 3e 3c 2f table></table></
0680: 61 74 74 72 2d 74 65 73 74 3e 27 29 0a 0a 20 20 attr-test>')..
0690: 20 20 63 6f 6e 74 65 6e 74 20 3d 20 72 69 6f 74 content = riot
06a0: 2e 72 65 6e 64 65 72 28 27 61 74 74 72 2d 74 65 .render('attr-te
06b0: 73 74 27 2c 20 7b 20 69 73 43 68 65 63 6b 65 64 st', { isChecked
06c0: 3a 20 6e 75 6c 6c 2c 20 63 68 65 63 6b 62 6f 78 : null, checkbox
06d0: 49 64 3a 20 30 2c 20 69 6e 63 6c 75 64 65 54 61 Id: 0, includeTa
06e0: 62 6c 65 3a 20 74 72 75 65 2c 20 74 61 62 6c 65 ble: true, table
06f0: 42 6f 72 64 65 72 3a 20 30 20 7d 29 0a 20 20 20 Border: 0 }).
0700: 20 65 78 70 65 63 74 28 63 6f 6e 74 65 6e 74 29 expect(content)
0710: 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 3c 61 .to.be.equal('<a
0720: 74 74 72 2d 74 65 73 74 3e 3c 69 6e 70 75 74 20 ttr-test><input
0730: 74 79 70 65 3d 22 63 68 65 63 6b 62 6f 78 22 20 type="checkbox"
0740: 69 64 3d 22 30 22 3e 20 3c 74 61 62 6c 65 20 62 id="0"> <table b
0750: 6f 72 64 65 72 3d 22 30 22 3e 3c 2f 74 61 62 6c order="0"></tabl
0760: 65 3e 3c 2f 61 74 74 72 2d 74 65 73 74 3e 27 29 e></attr-test>')
0770: 0a 0a 20 20 20 20 63 6f 6e 74 65 6e 74 20 3d 20 .. content =
0780: 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 61 74 74 riot.render('att
0790: 72 2d 74 65 73 74 27 2c 20 7b 20 69 73 43 68 65 r-test', { isChe
07a0: 63 6b 65 64 3a 20 30 2c 20 63 68 65 63 6b 62 6f cked: 0, checkbo
07b0: 78 49 64 3a 20 39 39 20 7d 29 0a 20 20 20 20 65 xId: 99 }). e
07c0: 78 70 65 63 74 28 63 6f 6e 74 65 6e 74 29 2e 74 xpect(content).t
07d0: 6f 2e 62 65 2e 65 71 75 61 6c 28 27 3c 61 74 74 o.be.equal('<att
07e0: 72 2d 74 65 73 74 3e 3c 69 6e 70 75 74 20 74 79 r-test><input ty
07f0: 70 65 3d 22 63 68 65 63 6b 62 6f 78 22 20 69 64 pe="checkbox" id
0800: 3d 22 39 39 22 3e 20 3c 2f 61 74 74 72 2d 74 65 ="99"> </attr-te
0810: 73 74 3e 27 29 0a 20 20 7d 29 0a 0a 20 20 69 74 st>'). }).. it
0820: 28 27 72 65 6e 64 65 72 20 74 61 67 3a 20 6c 6f ('render tag: lo
0830: 6f 70 2d 63 68 69 6c 64 27 2c 20 66 75 6e 63 74 op-child', funct
0840: 69 6f 6e 28 29 20 7b 0a 20 20 20 20 76 61 72 20 ion() {. var
0850: 6c 70 63 20 3d 20 72 69 6f 74 2e 72 65 6e 64 65 lpc = riot.rende
0860: 72 28 27 6c 6f 6f 70 2d 63 68 69 6c 64 27 29 0a r('loop-child').
0870: 20 20 20 20 76 61 72 20 24 20 3d 20 63 68 65 65 var $ = chee
0880: 72 69 6f 2e 6c 6f 61 64 28 6c 70 63 29 0a 20 20 rio.load(lpc).
0890: 20 20 65 78 70 65 63 74 28 24 28 27 6c 6f 6f 70 expect($('loop
08a0: 65 64 2d 63 68 69 6c 64 27 29 2e 6c 65 6e 67 74 ed-child').lengt
08b0: 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 32 h).to.be.equal(2
08c0: 29 0a 20 20 20 20 76 61 72 20 68 33 73 20 3d 20 ). var h3s =
08d0: 24 28 27 68 33 27 29 0a 20 20 20 20 65 78 70 65 $('h3'). expe
08e0: 63 74 28 68 33 73 2e 6c 65 6e 67 74 68 29 2e 74 ct(h3s.length).t
08f0: 6f 2e 62 65 2e 65 71 75 61 6c 28 32 29 0a 20 20 o.be.equal(2).
0900: 20 20 65 78 70 65 63 74 28 68 33 73 2e 66 69 72 expect(h3s.fir
0910: 73 74 28 29 2e 74 65 78 74 28 29 29 2e 74 6f 2e st().text()).to.
0920: 62 65 2e 65 71 75 61 6c 28 27 6f 6e 65 27 29 0a be.equal('one').
0930: 20 20 20 20 65 78 70 65 63 74 28 68 33 73 2e 6c expect(h3s.l
0940: 61 73 74 28 29 2e 74 65 78 74 28 29 29 2e 74 6f ast().text()).to
0950: 2e 62 65 2e 65 71 75 61 6c 28 27 74 77 6f 27 29 .be.equal('two')
0960: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 72 65 6e . }).. it('ren
0970: 64 65 72 20 74 61 67 3a 20 6c 6f 6f 70 2d 72 65 der tag: loop-re
0980: 70 6c 61 63 65 27 2c 20 66 75 6e 63 74 69 6f 6e place', function
0990: 28 29 20 7b 0a 20 20 20 20 76 61 72 20 6c 70 72 () {. var lpr
09a0: 20 3d 20 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 = riot.render('
09b0: 6c 6f 6f 70 2d 72 65 70 6c 61 63 65 27 29 0a 20 loop-replace').
09c0: 20 20 20 76 61 72 20 24 20 3d 20 63 68 65 65 72 var $ = cheer
09d0: 69 6f 2e 6c 6f 61 64 28 6c 70 72 29 0a 20 20 20 io.load(lpr).
09e0: 20 76 61 72 20 65 6c 73 20 3d 20 24 28 27 73 74 var els = $('st
09f0: 72 6f 6e 67 27 29 0a 20 20 20 20 65 78 70 65 63 rong'). expec
0a00: 74 28 65 6c 73 2e 6c 65 6e 67 74 68 29 2e 74 6f t(els.length).to
0a10: 2e 62 65 2e 65 71 75 61 6c 28 33 29 0a 20 20 20 .be.equal(3).
0a20: 20 65 78 70 65 63 74 28 65 6c 73 2e 66 69 72 73 expect(els.firs
0a30: 74 28 29 2e 74 65 78 74 28 29 29 2e 74 6f 2e 62 t().text()).to.b
0a40: 65 2e 65 71 75 61 6c 28 27 61 27 29 0a 20 20 20 e.equal('a').
0a50: 20 65 78 70 65 63 74 28 65 6c 73 2e 66 69 72 73 expect(els.firs
0a60: 74 28 29 2e 6e 65 78 74 28 29 2e 74 65 78 74 28 t().next().text(
0a70: 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 )).to.be.equal('
0a80: 39 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65 9'). expect(e
0a90: 6c 73 2e 6c 61 73 74 28 29 2e 74 65 78 74 28 29 ls.last().text()
0aa0: 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 33 ).to.be.equal('3
0ab0: 27 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 72 '). }).. it('r
0ac0: 65 6e 64 65 72 20 74 61 67 3a 20 62 6c 6f 67 20 ender tag: blog
0ad0: 28 75 73 69 6e 67 20 79 69 65 6c 64 29 27 2c 20 (using yield)',
0ae0: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 function() {.
0af0: 20 76 61 72 20 62 6c 67 20 3d 20 72 69 6f 74 2e var blg = riot.
0b00: 72 65 6e 64 65 72 28 27 62 6c 6f 67 27 29 0a 20 render('blog').
0b10: 20 20 20 76 61 72 20 24 20 3d 20 63 68 65 65 72 var $ = cheer
0b20: 69 6f 2e 6c 6f 61 64 28 62 6c 67 29 0a 20 20 20 io.load(blg).
0b30: 20 76 61 72 20 65 6c 73 20 3d 20 24 28 27 68 32 var els = $('h2
0b40: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 65 6c '). expect(el
0b50: 73 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e s.length).to.be.
0b60: 65 71 75 61 6c 28 32 29 0a 20 20 20 20 65 78 70 equal(2). exp
0b70: 65 63 74 28 65 6c 73 2e 66 69 72 73 74 28 29 2e ect(els.first().
0b80: 74 65 78 74 28 29 29 2e 74 6f 2e 62 65 2e 65 71 text()).to.be.eq
0b90: 75 61 6c 28 27 70 6f 73 74 20 31 27 29 0a 20 20 ual('post 1').
0ba0: 20 20 65 78 70 65 63 74 28 65 6c 73 2e 6c 61 73 expect(els.las
0bb0: 74 28 29 2e 74 65 78 74 28 29 29 2e 74 6f 2e 62 t().text()).to.b
0bc0: 65 2e 65 71 75 61 6c 28 27 70 6f 73 74 20 32 27 e.equal('post 2'
0bd0: 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 74 65 ). }).. it('te
0be0: 6e 64 65 72 20 74 61 67 3a 20 6c 6f 6f 70 20 74 nder tag: loop t
0bf0: 61 62 6c 65 27 2c 20 66 75 6e 63 74 69 6f 6e 28 able', function(
0c00: 29 20 7b 0a 20 20 20 20 76 61 72 20 74 62 6c 20 ) {. var tbl
0c10: 3d 20 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 74 = riot.render('t
0c20: 61 62 6c 65 2d 6c 6f 6f 70 2d 65 78 74 72 61 2d able-loop-extra-
0c30: 72 6f 77 27 29 2c 0a 20 20 20 20 20 20 24 20 3d row'),. $ =
0c40: 20 63 68 65 65 72 69 6f 2e 6c 6f 61 64 28 74 62 cheerio.load(tb
0c50: 6c 29 0a 20 20 20 20 65 78 70 65 63 74 28 24 28 l). expect($(
0c60: 27 74 61 62 6c 65 20 74 72 27 29 2e 6c 65 6e 67 'table tr').leng
0c70: 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 th).to.be.equal(
0c80: 35 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 72 5). }).. it('r
0c90: 65 6e 64 65 72 20 74 61 67 3a 20 73 69 6d 70 6c ender tag: simpl
0ca0: 65 20 62 6c 6f 63 6b 20 28 75 73 69 6e 67 20 79 e block (using y
0cb0: 69 65 6c 64 29 27 2c 20 66 75 6e 63 74 69 6f 6e ield)', function
0cc0: 28 29 20 7b 0a 20 20 20 20 76 61 72 20 62 6c 6b () {. var blk
0cd0: 20 3d 20 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 = riot.render('
0ce0: 62 6c 6f 63 6b 27 29 0a 20 20 20 20 76 61 72 20 block'). var
0cf0: 24 20 3d 20 63 68 65 65 72 69 6f 2e 6c 6f 61 64 $ = cheerio.load
0d00: 28 62 6c 6b 29 0a 20 20 20 20 65 78 70 65 63 74 (blk). expect
0d10: 28 24 28 27 62 6c 6f 63 6b 27 29 2e 6c 65 6e 67 ($('block').leng
0d20: 74 68 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 th).to.be.equal(
0d30: 31 29 0a 20 20 20 20 65 78 70 65 63 74 28 24 28 1). expect($(
0d40: 27 79 6f 79 6f 27 29 2e 6c 65 6e 67 74 68 29 2e 'yoyo').length).
0d50: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 31 29 0a 20 to.be.equal(1).
0d60: 20 20 20 65 78 70 65 63 74 28 24 28 27 79 6f 79 expect($('yoy
0d70: 6f 27 29 2e 68 74 6d 6c 28 29 29 2e 74 6f 2e 62 o').html()).to.b
0d80: 65 2e 65 71 75 61 6c 28 27 48 65 6c 6c 6f 20 57 e.equal('Hello W
0d90: 6f 72 6c 64 21 27 29 0a 20 20 7d 29 0a 0a 20 20 orld!'). })..
0da0: 69 74 28 27 72 65 6e 64 65 72 20 74 61 67 3a 20 it('render tag:
0db0: 79 69 65 6c 64 20 77 69 74 68 20 6e 6f 20 68 74 yield with no ht
0dc0: 6d 6c 20 63 6f 6e 74 65 6e 74 27 2c 20 66 75 6e ml content', fun
0dd0: 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 76 61 ction() {. va
0de0: 72 20 62 6c 6b 20 3d 20 72 69 6f 74 2e 72 65 6e r blk = riot.ren
0df0: 64 65 72 28 27 79 69 65 6c 64 2d 65 6d 70 74 79 der('yield-empty
0e00: 27 29 0a 20 20 20 20 65 78 70 65 63 74 28 62 6c '). expect(bl
0e10: 6b 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 k).to.be.equal('
0e20: 3c 79 69 65 6c 64 2d 65 6d 70 74 79 3e 3c 2f 79 <yield-empty></y
0e30: 69 65 6c 64 2d 65 6d 70 74 79 3e 27 29 0a 20 20 ield-empty>').
0e40: 7d 29 0a 0a 20 20 69 74 28 27 72 65 6e 64 65 72 }).. it('render
0e50: 20 74 61 67 3a 20 73 76 67 20 6c 6f 6f 70 73 27 tag: svg loops'
0e60: 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 , function() {.
0e70: 20 20 20 76 61 72 20 73 76 67 20 3d 20 72 69 6f var svg = rio
0e80: 74 2e 72 65 6e 64 65 72 28 27 6c 6f 6f 70 2d 73 t.render('loop-s
0e90: 76 67 2d 6e 6f 64 65 73 27 29 0a 20 20 20 20 76 vg-nodes'). v
0ea0: 61 72 20 24 20 3d 20 63 68 65 65 72 69 6f 2e 6c ar $ = cheerio.l
0eb0: 6f 61 64 28 73 76 67 29 0a 20 20 20 20 65 78 70 oad(svg). exp
0ec0: 65 63 74 28 24 28 27 63 69 72 63 6c 65 27 29 2e ect($('circle').
0ed0: 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 65 2e 65 71 length).to.be.eq
0ee0: 75 61 6c 28 35 29 0a 20 20 7d 29 0a 0a 20 20 69 ual(5). }).. i
0ef0: 74 28 27 72 65 6e 64 65 72 20 74 61 67 3a 20 6c t('render tag: l
0f00: 6f 6f 70 73 20 68 61 76 69 6e 67 20 63 6f 6e 64 oops having cond
0f10: 69 74 69 6f 6e 61 6c 20 64 69 72 65 63 74 69 76 itional directiv
0f20: 65 73 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 es', function()
0f30: 7b 0a 20 20 20 20 76 61 72 20 74 61 67 20 3d 20 {. var tag =
0f40: 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 6c 6f 6f riot.render('loo
0f50: 70 2d 63 6f 6e 64 69 74 69 6f 6e 61 6c 27 29 0a p-conditional').
0f60: 20 20 20 20 76 61 72 20 24 20 3d 20 63 68 65 65 var $ = chee
0f70: 72 69 6f 2e 6c 6f 61 64 28 74 61 67 29 0a 20 20 rio.load(tag).
0f80: 20 20 65 78 70 65 63 74 28 24 28 27 6c 6f 6f 70 expect($('loop
0f90: 2d 63 6f 6e 64 69 74 69 6f 6e 61 6c 2d 69 74 65 -conditional-ite
0fa0: 6d 27 29 2e 6c 65 6e 67 74 68 29 2e 74 6f 2e 62 m').length).to.b
0fb0: 65 2e 65 71 75 61 6c 28 32 29 0a 20 20 7d 29 0a e.equal(2). }).
0fc0: 0a 20 20 69 74 28 27 72 65 6e 64 65 72 20 74 61 . it('render ta
0fd0: 67 3a 20 69 6e 70 75 74 2c 6f 70 74 69 6f 6e 2c g: input,option,
0fe0: 74 65 78 74 61 72 65 61 20 74 61 67 73 20 68 61 textarea tags ha
0ff0: 76 69 6e 67 20 65 78 70 72 65 73 73 69 6f 6e 73 ving expressions
1000: 20 61 73 20 76 61 6c 75 65 27 2c 20 66 75 6e 63 as value', func
1010: 74 69 6f 6e 28 29 20 7b 0a 20 20 20 20 76 61 72 tion() {. var
1020: 20 66 72 6d 20 3d 20 72 69 6f 74 2e 72 65 6e 64 frm = riot.rend
1030: 65 72 28 27 66 6f 72 6d 2d 63 6f 6e 74 72 6f 6c er('form-control
1040: 73 27 2c 20 7b 20 74 65 78 74 3a 20 27 6d 79 2d s', { text: 'my-
1050: 76 61 6c 75 65 27 2c 20 62 6f 6f 6c 3a 20 74 72 value', bool: tr
1060: 75 65 20 7d 29 0a 20 20 20 20 76 61 72 20 24 20 ue }). var $
1070: 3d 20 63 68 65 65 72 69 6f 2e 6c 6f 61 64 28 66 = cheerio.load(f
1080: 72 6d 29 0a 20 20 20 20 65 78 70 65 63 74 28 24 rm). expect($
1090: 28 27 69 6e 70 75 74 5b 74 79 70 65 3d 22 74 65 ('input[type="te
10a0: 78 74 22 5d 27 29 2e 76 61 6c 28 29 29 2e 74 6f xt"]').val()).to
10b0: 2e 62 65 2e 65 71 75 61 6c 28 27 6d 79 2d 76 61 .be.equal('my-va
10c0: 6c 75 65 27 29 0a 20 20 20 20 65 78 70 65 63 74 lue'). expect
10d0: 28 24 28 27 73 65 6c 65 63 74 20 6f 70 74 69 6f ($('select optio
10e0: 6e 3a 73 65 6c 65 63 74 65 64 27 29 2e 76 61 6c n:selected').val
10f0: 28 29 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c 28 ()).to.be.equal(
1100: 27 6d 79 2d 76 61 6c 75 65 27 29 0a 20 20 20 20 'my-value').
1110: 65 78 70 65 63 74 28 24 28 27 74 65 78 74 61 72 expect($('textar
1120: 65 61 5b 6e 61 6d 65 3d 22 74 78 74 61 31 22 5d ea[name="txta1"]
1130: 27 29 2e 76 61 6c 28 29 29 2e 74 6f 2e 62 65 2e ').val()).to.be.
1140: 65 71 75 61 6c 28 27 6d 79 2d 76 61 6c 75 65 27 equal('my-value'
1150: 29 0a 20 20 20 20 65 78 70 65 63 74 28 24 28 27 ). expect($('
1160: 74 65 78 74 61 72 65 61 5b 6e 61 6d 65 3d 22 74 textarea[name="t
1170: 78 74 61 32 22 5d 27 29 2e 76 61 6c 28 29 29 2e xta2"]').val()).
1180: 74 6f 2e 62 65 2e 65 71 75 61 6c 28 27 27 29 0a to.be.equal('').
1190: 20 20 7d 29 0a 0a 20 20 69 74 28 27 72 65 6e 64 }).. it('rend
11a0: 65 72 20 74 61 67 3a 20 6c 6f 6f 70 65 64 20 76 er tag: looped v
11b0: 69 72 74 75 61 6c 20 74 61 67 73 20 67 65 74 20 irtual tags get
11c0: 70 72 6f 70 65 72 6c 79 20 72 65 6e 64 65 72 65 properly rendere
11d0: 64 27 2c 20 66 75 6e 63 74 69 6f 6e 28 29 20 7b d', function() {
11e0: 0a 20 20 20 20 76 61 72 20 74 61 67 20 3d 20 72 . var tag = r
11f0: 69 6f 74 2e 72 65 6e 64 65 72 28 27 6c 6f 6f 70 iot.render('loop
1200: 2d 76 69 72 74 75 61 6c 27 29 0a 20 20 20 20 76 -virtual'). v
1210: 61 72 20 24 20 3d 20 63 68 65 65 72 69 6f 2e 6c ar $ = cheerio.l
1220: 6f 61 64 28 74 61 67 29 0a 20 20 20 20 65 78 70 oad(tag). exp
1230: 65 63 74 28 24 28 27 64 74 27 29 29 2e 74 6f 2e ect($('dt')).to.
1240: 68 61 76 65 2e 6c 65 6e 67 74 68 28 32 29 0a 20 have.length(2).
1250: 20 20 20 65 78 70 65 63 74 28 24 28 27 64 64 27 expect($('dd'
1260: 29 29 2e 74 6f 2e 68 61 76 65 2e 6c 65 6e 67 74 )).to.have.lengt
1270: 68 28 32 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 h(2). }).. it(
1280: 27 6c 6f 61 64 20 74 61 67 20 77 69 74 68 20 63 'load tag with c
1290: 75 73 74 6f 6d 20 6f 70 74 69 6f 6e 73 27 2c 20 ustom options',
12a0: 66 75 6e 63 74 69 6f 6e 28 29 20 7b 0a 20 20 20 function() {.
12b0: 20 76 61 72 20 74 61 67 20 3d 20 72 69 6f 74 2e var tag = riot.
12c0: 72 65 71 75 69 72 65 28 70 61 74 68 2e 72 65 73 require(path.res
12d0: 6f 6c 76 65 28 5f 5f 64 69 72 6e 61 6d 65 2c 20 olve(__dirname,
12e0: 27 2e 2e 2f 2e 2e 2f 74 61 67 2f 7e 63 75 73 74 '../../tag/~cust
12f0: 6f 6d 2d 70 61 72 73 65 72 73 2e 74 61 67 27 29 om-parsers.tag')
1300: 2c 20 7b 20 65 78 63 6c 75 64 65 3a 20 5b 27 68 , { exclude: ['h
1310: 74 6d 6c 27 2c 20 27 63 73 73 27 5d 20 7d 29 0a tml', 'css'] }).
1320: 20 20 20 20 76 61 72 20 74 6d 70 6c 20 3d 20 72 var tmpl = r
1330: 69 6f 74 2e 72 65 6e 64 65 72 28 27 63 75 73 74 iot.render('cust
1340: 6f 6d 2d 70 61 72 73 65 72 73 27 29 0a 0a 20 20 om-parsers')..
1350: 20 20 65 78 70 65 63 74 28 74 61 67 29 2e 74 6f expect(tag).to
1360: 2e 62 65 2e 65 71 75 61 6c 28 27 63 75 73 74 6f .be.equal('custo
1370: 6d 2d 70 61 72 73 65 72 73 27 29 0a 20 20 20 20 m-parsers').
1380: 65 78 70 65 63 74 28 74 6d 70 6c 29 2e 74 6f 2e expect(tmpl).to.
1390: 62 65 2e 65 71 75 61 6c 28 27 3c 63 75 73 74 6f be.equal('<custo
13a0: 6d 2d 70 61 72 73 65 72 73 3e 3c 2f 63 75 73 74 m-parsers></cust
13b0: 6f 6d 2d 70 61 72 73 65 72 73 3e 27 29 0a 0a 20 om-parsers>')..
13c0: 20 20 20 74 61 67 20 3d 20 72 69 6f 74 2e 72 65 tag = riot.re
13d0: 71 75 69 72 65 28 70 61 74 68 2e 72 65 73 6f 6c quire(path.resol
13e0: 76 65 28 5f 5f 64 69 72 6e 61 6d 65 2c 20 27 2e ve(__dirname, '.
13f0: 2e 2f 2e 2e 2f 74 61 67 2f 7e 63 75 73 74 6f 6d ./../tag/~custom
1400: 2d 70 61 72 73 65 72 73 2e 74 61 67 27 29 29 0a -parsers.tag')).
1410: 20 20 20 20 74 6d 70 6c 20 3d 20 72 69 6f 74 2e tmpl = riot.
1420: 72 65 6e 64 65 72 28 27 63 75 73 74 6f 6d 2d 70 render('custom-p
1430: 61 72 73 65 72 73 27 29 0a 0a 20 20 20 20 65 78 arsers').. ex
1440: 70 65 63 74 28 74 61 67 29 2e 74 6f 2e 62 65 2e pect(tag).to.be.
1450: 65 71 75 61 6c 28 27 63 75 73 74 6f 6d 2d 70 61 equal('custom-pa
1460: 72 73 65 72 73 27 29 0a 20 20 20 20 65 78 70 65 rsers'). expe
1470: 63 74 28 74 6d 70 6c 29 2e 74 6f 2e 62 65 2e 65 ct(tmpl).to.be.e
1480: 71 75 61 6c 28 27 3c 63 75 73 74 6f 6d 2d 70 61 qual('<custom-pa
1490: 72 73 65 72 73 3e 3c 70 3e 68 69 3c 2f 70 3e 3c rsers><p>hi</p><
14a0: 2f 63 75 73 74 6f 6d 2d 70 61 72 73 65 72 73 3e /custom-parsers>
14b0: 27 29 0a 0a 20 20 20 20 65 78 70 65 63 74 28 72 ').. expect(r
14c0: 65 71 75 69 72 65 28 27 2e 2e 2f 2e 2e 2f 2e 2e equire('../../..
14d0: 2f 6c 69 62 2f 73 65 72 76 65 72 27 29 29 2e 74 /lib/server')).t
14e0: 6f 2e 62 65 2e 6e 6f 74 2e 65 71 75 61 6c 28 27 o.be.not.equal('
14f0: 63 75 73 74 6f 6d 2d 70 61 72 73 65 72 73 27 29 custom-parsers')
1500: 0a 20 20 7d 29 0a 0a 20 20 69 74 28 27 4c 6f 61 . }).. it('Loa
1510: 64 20 74 61 67 73 20 63 6f 6e 74 61 69 6e 69 6e d tags containin
1520: 67 20 6e 65 73 74 65 64 20 72 65 71 75 69 72 65 g nested require
1530: 20 63 61 6c 6c 73 27 2c 20 66 75 6e 63 74 69 6f calls', functio
1540: 6e 28 29 20 7b 0a 20 20 20 20 76 61 72 20 74 61 n() {. var ta
1550: 67 20 3d 20 72 65 71 75 69 72 65 28 70 61 74 68 g = require(path
1560: 2e 72 65 73 6f 6c 76 65 28 5f 5f 64 69 72 6e 61 .resolve(__dirna
1570: 6d 65 2c 20 27 2e 2e 2f 2e 2e 2f 74 61 67 2f 7e me, '../../tag/~
1580: 69 6d 70 6f 72 74 2d 74 61 67 73 2e 74 61 67 27 import-tags.tag'
1590: 29 29 0a 20 20 20 20 76 61 72 20 74 6d 70 6c 20 )). var tmpl
15a0: 3d 20 72 69 6f 74 2e 72 65 6e 64 65 72 28 27 69 = riot.render('i
15b0: 6d 70 6f 72 74 2d 74 61 67 73 27 29 0a 0a 20 20 mport-tags')..
15c0: 20 20 65 78 70 65 63 74 28 74 61 67 29 2e 74 6f expect(tag).to
15d0: 2e 62 65 2e 65 71 75 61 6c 28 27 69 6d 70 6f 72 .be.equal('impor
15e0: 74 2d 74 61 67 73 27 29 0a 20 20 20 20 65 78 70 t-tags'). exp
15f0: 65 63 74 28 74 6d 70 6c 29 2e 74 6f 2e 68 61 76 ect(tmpl).to.hav
1600: 65 2e 6c 65 6e 67 74 68 0a 20 20 7d 29 0a 0a 20 e.length. })..
1610: 20 69 74 28 27 72 65 6e 64 65 72 20 74 61 67 3a it('render tag:
1620: 20 61 73 79 6e 63 20 72 65 6e 64 65 72 69 6e 67 async rendering
1630: 27 2c 20 66 75 6e 63 74 69 6f 6e 28 64 6f 6e 65 ', function(done
1640: 29 20 7b 0a 20 20 20 20 72 69 6f 74 2e 72 65 6e ) {. riot.ren
1650: 64 65 72 41 73 79 6e 63 28 27 61 73 79 6e 63 2d derAsync('async-
1660: 72 65 6e 64 65 72 69 6e 67 27 29 2e 74 68 65 6e rendering').then
1670: 28 66 75 6e 63 74 69 6f 6e 28 74 6d 70 6c 29 20 (function(tmpl)
1680: 7b 0a 20 20 20 20 20 20 65 78 70 65 63 74 28 74 {. expect(t
1690: 6d 70 6c 29 2e 74 6f 2e 62 65 2e 65 71 75 61 6c mpl).to.be.equal
16a0: 28 27 3c 61 73 79 6e 63 2d 72 65 6e 64 65 72 69 ('<async-renderi
16b0: 6e 67 3e 3c 70 3e 68 69 3c 2f 70 3e 3c 2f 61 73 ng><p>hi</p></as
16c0: 79 6e 63 2d 72 65 6e 64 65 72 69 6e 67 3e 27 29 ync-rendering>')
16d0: 0a 20 20 20 20 20 20 64 6f 6e 65 28 29 0a 20 20 . done().
16e0: 20 20 7d 29 0a 20 20 7d 29 0a 0a 20 20 69 74 28 }). }).. it(
16f0: 27 72 65 6e 64 65 72 20 74 61 67 3a 20 61 73 79 'render tag: asy
1700: 6e 63 20 72 65 6e 64 65 72 69 6e 67 20 63 61 6e nc rendering can
1710: 20 74 69 6d 65 6f 75 74 27 2c 20 66 75 6e 63 74 timeout', funct
1720: 69 6f 6e 28 64 6f 6e 65 29 20 7b 0a 20 20 20 20 ion(done) {.
1730: 72 69 6f 74 2e 72 65 6e 64 65 72 41 73 79 6e 63 riot.renderAsync
1740: 28 27 61 73 79 6e 63 2d 72 65 6e 64 65 72 69 6e ('async-renderin
1750: 67 27 2c 20 7b 20 64 65 6c 61 79 3a 20 31 30 31 g', { delay: 101
1760: 30 20 7d 29 2e 63 61 74 63 68 28 66 75 6e 63 74 0 }).catch(funct
1770: 69 6f 6e 28 65 29 20 7b 0a 20 20 20 20 20 20 65 ion(e) {. e
1780: 78 70 65 63 74 28 65 29 2e 74 6f 2e 68 61 76 65 xpect(e).to.have
1790: 2e 6c 65 6e 67 74 68 0a 20 20 20 20 20 20 64 6f .length. do
17a0: 6e 65 28 29 0a 20 20 20 20 7d 29 0a 20 20 7d 29 ne(). }). })
17b0: 0a 7d 29 0a .}).