Use $$ -> to render ad-hoc document fragments

Also eliminate stdlib/template directory which held code related to
SpacePen's precursor framework.
This commit is contained in:
Nathan Sobo
2012-02-06 16:19:35 -07:00
parent c712f598e5
commit bb640dd342
9 changed files with 48 additions and 238 deletions

View File

@@ -1,14 +1,14 @@
$$ = require 'template/builder'
{$$} = require 'space-pen'
nakedLoad 'jasmine'
nakedLoad 'jasmine-html'
nakedLoad 'jasmine-focused'
$ = require 'jquery'
$('head').append $$.render ->
$('head').append $$ ->
@link rel: "stylesheet", type: "text/css", href: "static/jasmine.css"
$('body').append $$.render ->
$('body').append $$ ->
@div id: 'jasmine_runner'
@div id: 'jasmine-content'

View File

@@ -1,75 +0,0 @@
Builder = require 'template/builder'
describe "Builder", ->
builder = null
beforeEach -> builder = new Builder
describe "tag class methods", ->
it "calls render, assuming the arguments to the current method as the first tag", ->
fragment =
Builder.div ->
@ol class: 'cool-list', =>
@li()
@li()
expect(fragment).toMatchSelector('div')
expect(fragment.find('ol.cool-list')).toExist()
expect(fragment.find('li').length).toBe 2
describe "@render", ->
it "runs the given function in a fresh builder instance and returns the resulting view fragment", ->
fragment =
Builder.render ->
@div =>
@ol class: 'cool-list', =>
@li()
@li()
expect(fragment).toMatchSelector('div')
expect(fragment.find('ol.cool-list')).toExist()
expect(fragment.find('li').length).toBe 2
describe ".tag(name, args...)", ->
it "can generate simple tags", ->
builder.tag 'div'
expect(builder.toHtml()).toBe "<div></div>"
builder.reset()
builder.tag 'ol'
expect(builder.toHtml()).toBe "<ol></ol>"
it "can generate tags with content", ->
builder.tag 'ol', ->
builder.tag 'li'
builder.tag 'li'
expect(builder.toHtml()).toBe "<ol><li></li><li></li></ol>"
it "can generate tags with text", ->
builder.tag 'div', "hello"
expect(builder.toHtml()).toBe "<div>hello</div>"
builder.reset()
builder.tag 'div', 22
expect(builder.toHtml()).toBe "<div>22</div>"
it "HTML escapes tag text", ->
builder.tag('div', "<br/>")
expect(builder.toHtml()).toBe "<div>&lt;br/&gt;</div>"
it "can generate tags with attributes", ->
builder.tag 'div', id: 'foo', class: 'bar'
fragment = builder.toFragment()
expect(fragment.attr('id')).toBe 'foo'
expect(fragment.attr('class')).toBe 'bar'
it "can generate self-closing tags", ->
builder.tag 'br', id: 'foo'
expect(builder.toHtml()).toBe '<br id="foo">'
describe ".raw(text)", ->
it "does not escape html entities", ->
builder.raw '&nbsp;'
expect(builder.toHtml()).toBe '&nbsp;'