We design and develop ambitious web and mobile applications,
A more official portfolio page is on its way, but in the meantime, check out
# Test Setup: Set up an environment that'll work for both Node and Qunit tests. Ember = window?.Emblem || @Emblem || {} # These are needed for the full version ember to load properly LoadedEmber = LoadedEmber || {} Ember.Handlebars = LoadedEmber.Handlebars Ember.warn = LoadedEmber.warn if Emblem? # Qunit testing _equal = equal equals = equal = (a, b, msg) -> # Allow exec with missing message params _equal(a, b, msg || '') # In QUnit, we use module() instead of nonexistent suite() window.suite = module else # Setup for Node package testing Handlebars = require('handlebars') EmberHandlebars = require('./resources/ember-template-compiler.js').EmberHandlebars Emblem = require('../lib/emblem') # TODO: replace with real expect() `expect = function() {};` {equal, equals, ok, throws} = require("assert") unless CompilerContext? # Note that this doesn't have the same context separation as the rspec test. # Both should be run for full acceptance of the two libary modes. CompilerContext = compile: (template, options) -> Emblem.compile(Handlebars, template, options) supportsEachHelperDataKeywords = Handlebars.VERSION.slice(0, 3) >= 1.2 supportsSubexpressions = Handlebars.VERSION.slice(0, 3) >= 1.3 precompileEmber = (emblem) -> Emblem.precompile(EmberHandlebars, emblem).toString() shouldEmberPrecompileToHelper = (emblem, helper = 'bind-attr') -> result = precompileEmber emblem ok (result.match "helpers.#{helper}") or (result.match "helpers\\['#{helper}'\\]") result shouldCompileToString = (string, hashOrArray, expected) -> if hashOrArray.constructor == String shouldCompileToWithPartials(string, {}, false, hashOrArray, null, true) else shouldCompileToWithPartials(string, hashOrArray, false, expected, null, true) shouldCompileTo = (string, hashOrArray, expected, message) -> if hashOrArray.constructor == String shouldCompileToWithPartials(string, {}, false, hashOrArray, message) else shouldCompileToWithPartials(string, hashOrArray, false, expected, message) shouldCompileToWithPartials = (string, hashOrArray, partials, expected, message, strings) -> options = null if strings options = {} options.stringParams = true result = compileWithPartials(string, hashOrArray, partials, options) equal(result, expected, "'" + result + "' should === '" + expected + "': " + message) compileWithPartials = (string, hashOrArray, partials, options = {}) -> template = CompilerContext.compile(string, options) if Object::toString.call(hashOrArray) == "[object Array]" if helpers = hashOrArray[1] for prop of Handlebars.helpers helpers[prop] = helpers[prop] || Handlebars.helpers[prop] ary = [] ary.push(hashOrArray[0]) ary.push helpers: hashOrArray[1] partials: hashOrArray[2] else ary = [hashOrArray] template.apply(this, ary) shouldThrow = (fn, exMessage) -> caught = false try fn() catch e caught = true if exMessage ok e.message.match(exMessage), "exception message matched" ok(caught, "an exception was thrown") Handlebars.registerHelper 'echo', (param) -> "ECHO #{param}" suite "html one-liners" test "element only", -> shouldCompileTo "p", "
" test "with text", -> shouldCompileTo "p Hello", "Hello
" test "with more complex text", -> shouldCompileTo "p Hello, how's it going with you today?", "Hello, how's it going with you today?
" test "with trailing space", -> shouldCompileTo "p Hello ", "Hello
" suite "html multi-lines" test "two lines", -> emblem = """ p This is pretty cool. """ shouldCompileTo emblem, "This is pretty cool.
" test "three lines", -> emblem = """ p This is pretty damn cool. """ shouldCompileTo emblem, "This is pretty damn cool.
" test "three lines w/ embedded html", -> emblem = """ p This is pretty damn cool. """ shouldCompileTo emblem, "This is pretty damn cool.
" test "indentation doesn't need to match starting inline content's", -> emblem = """ span Hello, How are you? """ shouldCompileTo emblem, "Hello, How are you?" test "indentation may vary between parent/child, must be consistent within inline-block", -> emblem = """ div span Hello, How are you? Excellent. p asd """ shouldCompileTo emblem, "asd
Hello,
Hello,
This is pretty cool.
Hello.
" suite '#{} syntax' test 'acts like {{}}', -> emblem = ''' span Yo #{foo}, I herd. ''' shouldCompileTo emblem, { foo: '123' }, "Yo <span>123</span>, I herd." test 'can start inline content', -> emblem = ''' span #{foo}, I herd. ''' shouldCompileTo emblem, { foo: "dawg" }, "dawg, I herd." test 'can end inline content', -> emblem = ''' span I herd #{foo} ''' shouldCompileTo emblem, { foo: "dawg" }, "I herd dawg" test "doesn't screw up parsing when # used in text nodes", -> emblem = ''' span OMG #YOLO ''' shouldCompileTo emblem, "OMG #YOLO" test "# can be only thing on line", -> emblem = ''' span # ''' shouldCompileTo emblem, "#" ### TODO: this test "can be escaped", -> emblem = ''' span #\\{yes} ''' shouldCompileTo emblem, '#{yes}' ### runTextLineSuite = (ch) -> sct = (emblem, obj, expected) -> unless expected? expected = obj obj = {} unless ch == '`' expected = expected.replace /\n/g, "" # Replace tabs with optional trailing whitespace. if ch == "'" expected = expected.replace /\t/g, " " else expected = expected.replace /\t/g, "" emblem = emblem.replace /_/g, ch shouldCompileTo emblem, obj, expected suite "text lines starting with '#{ch}'" test "basic", -> sct "_ What what", "What what\n\t" test "with html", -> sct '_ What what!', 'What what!\n\t' test "multiline", -> emblem = """ _ Blork Snork """ sct emblem, "Blork\nSnork\n\t" test "triple multiline", -> emblem = """ _ Blork Snork Bork """ sct emblem, "Blork\nSnork\nBork\n\t" test "quadruple multiline", -> emblem = """ _ Blork Snork Bork Fork """ sct emblem, "Blork\nSnork\nBork\nFork\n\t" test "multiline w/ trailing whitespace", -> emblem = """ _ Blork Snork """ sct emblem, "Blork \nSnork\n\t" test "secondline", -> emblem = """ _ Good """ sct emblem, "Good\n\t" test "secondline multiline", -> emblem = """ _ Good Bork """ sct emblem, "Good\nBork\n\t" test "with a mustache", -> emblem = """ _ Bork {{foo}}! """ sct emblem, { foo: "YEAH" }, 'Bork YEAH!\n\t' test "with mustaches", -> emblem = """ _ Bork {{foo}} {{{bar}}}! """ sct emblem, { foo: "YEAH", bar: "NO"}, 'Bork YEAH NO!\n\t' test "indented, then in a row", -> expect(0) return "PENDING" emblem = """ _ Good riddance2 dude gnar foo """ sct emblem, "Good\n riddance2\n dude\n gnar\n foo\n\t" test "indented, then in a row, then indented", -> expect(0) return "PENDING" emblem = """ _ Good riddance2 dude gnar foo far faz """ sct emblem, "Good \n riddance2 \n dude \n gnar \n foo \n far \n faz \n\t" test "uneven indentation megatest", -> expect(0) return "PENDING" emblem = """ _ Good riddance dude """ sct emblem, "Good\n riddance\ndude\n\t" emblem = """ _ Good riddance3 dude """ sct emblem, "Good\n riddance3\n dude\n\t" emblem = """ _ Good riddance dude """ sct emblem, "Good\nriddance\n dude\n\t" test "on each line", -> emblem = """ pre _ This _ should _ hopefully _ work, and work well. """ sct emblem, 'This\n\t should\n\t hopefully\n\t work, and work well.\n\t' test "with blank", -> emblem = """ pre _ This _ should _ _ hopefully _ work, and work well. """ sct emblem, '
This\n\t should\n\t\n\t hopefully\n\t work, and work well.\n\t' runTextLineSuite '|' runTextLineSuite '`' runTextLineSuite "'" suite "text line starting with angle bracket" test "can start with angle bracket html", -> emblem = """ Hello """ shouldCompileTo emblem, "Hello" test "can start with angle bracket html and go to multiple lines", -> emblem = """ Hello dude, what's up? """ shouldCompileTo emblem, "Hello dude, what's up?" suite "preprocessor" test "it strips out preceding whitespace", -> emblem = """ p Hello """ shouldCompileTo emblem, "
Hello
" test "it handles preceding indentation", -> emblem = " p Woot\n p Ha" shouldCompileTo emblem, "Woot
Ha
" test "it handles preceding indentation and newlines", -> emblem = "\n p Woot\n p Ha" shouldCompileTo emblem, "Woot
Ha
" test "it handles preceding indentation and newlines pt 2", -> emblem = " \n p Woot\n p Ha" shouldCompileTo emblem, "Woot
Ha
" suite "comments" test "it strips out single line '/' comments", -> emblem = """ p Hello / A comment h1 How are you? """ shouldCompileTo emblem, "Hello
Hello
Hello
Hello
Yessir nope.
" test "uneven indentation", -> emblem = """ / nop nope nope """ shouldCompileTo emblem, "" test "uneven indentation 2", -> emblem = """ / n no nop nope """ shouldCompileTo emblem, "" test "uneven indentation 3", -> emblem = """ / n no nop nope """ shouldCompileTo emblem, "" test "empty first line", -> emblem = """ / nop nope nope no """ shouldCompileTo emblem, "" test "on same line as html content", -> emblem = """ .container / This comment doesn't show up .row / Nor does this p Hello """ shouldCompileTo emblem, 'Hello
Hello p invalid
" test "it throws on half dedent", -> emblem = """ p span This is ok span This aint """ shouldThrow -> CompilerContext.compile emblem test "new indentation levels don't have to match parents'", -> emblem = """ p span div span yes """ shouldCompileTo emblem, "asd
" shouldCompileTo "p \nspan \n\ndiv\nspan", "" test "spaces after mustaches", -> shouldCompileTo "each foo \n p \n span", { foo: [1,2] }, "" suite "attribute shorthand" test "id shorthand", -> shouldCompileTo "#woot", '' shouldCompileTo "span#woot", '' test "class shorthand", -> shouldCompileTo ".woot", '' shouldCompileTo "span.woot", '' shouldCompileTo "span.woot.loot", '' test "class can come first", -> shouldCompileTo ".woot#hello", '' shouldCompileTo "span.woot#hello", '' shouldCompileTo "span.woot.loot#hello", '' shouldCompileTo "span.woot.loot#hello.boot", '' suite "full attributes - tags with content" test "class only", -> shouldCompileTo 'p class="yes" Blork', 'Blork
' test "id only", -> shouldCompileTo 'p id="yes" Hyeah', 'Hyeah
' test "class and id", -> shouldCompileTo 'p id="yes" class="no" Blork', 'Blork
' test "class and id and embedded html one-liner", -> shouldCompileTo 'p id="yes" class="no" One asd!', 'One asd!
' test "bracketed attributes", -> emblem = """ p [ id="yes" class="no" ] | Bracketed Attributes FTW! """ shouldCompileTo emblem, 'Bracketed Attributes FTW!
' test "bracketed text", -> emblem = """ p [ Bracketed text is cool ] """ shouldCompileTo emblem, '[ Bracketed text is cool ]
' test "bracketed text indented", -> emblem = """ p | [ Bracketed text is cool ] """ shouldCompileTo emblem, '[ Bracketed text is cool ]
' test "nesting", -> emblem = """ p class="hello" data-foo="gnarly" span Yes """ shouldCompileTo emblem, 'Yes
' suite "full attributes - mixed quotes" test "single empty", -> shouldCompileTo "p class=''", '' test "single full", -> shouldCompileTo "p class='woot yeah'", '' test "mixed", -> shouldCompileTo "p class='woot \"oof\" yeah'", '' suite "full attributes - tags without content" test "empty", -> shouldCompileTo 'p class=""', '' test "class only", -> shouldCompileTo 'p class="yes"', '' test "id only", -> shouldCompileTo 'p id="yes"', '' test "class and id", -> shouldCompileTo 'p id="yes" class="no"', '' suite "full attributes w/ mustaches" test "with mustache", -> shouldCompileTo 'p class="foo {{yes}}"', {yes: "ALEX"}, '' shouldCompileTo 'p class="foo {{yes}}" Hello', {yes: "ALEX"}, 'Hello
' emblem = """ p class="foo {{yes}}" | Hello """ shouldCompileTo emblem, {yes: "ALEX"}, 'Hello
' test "with mustache calling helper", -> shouldCompileTo 'p class="foo {{{echo "YES"}}}"', '' shouldCompileTo 'p class="foo #{echo "NO"} and {{{echo "YES"}}}" Hello', 'Hello
' emblem = """ p class="foo {{echo "BORF"}}" | Hello """ shouldCompileTo emblem, 'Hello
' suite "boolean attributes" test "static", -> shouldCompileTo 'p borf=true', '' shouldCompileTo 'p borf=true Woot', 'Woot
' shouldCompileTo 'p borf=false', '' shouldCompileTo 'p borf=false Nork', 'Nork
' shouldCompileTo 'option selected=true Thingeroo', '' #test "dynamic", -> ## TODO #shouldCompileTo 'p borf=foo', { foo: true }, '' #shouldCompileTo 'p borf=foo', { foo: false }, '' #shouldCompileTo 'p borf=foo Yeah', { foo: true }, 'Yeah
' #shouldCompileTo 'p borf=foo Naww', { foo: false }, 'Naww
' #shouldCompileTo 'p borf=foo Naww', { foo: null }, 'Naww
' #shouldCompileTo 'p borf=foo Naww', { foo: undefined }, 'Naww
' #shouldCompileTo 'p borf=foo Naww', { foo: 0 }, 'Naww
' suite "html nested" test "basic", -> emblem = """ p span Hello strong Hi div p Hooray """ shouldCompileTo emblem, 'HelloHi
Hooray
' test "empty nest w/ attribute shorthand", -> emblem = """ p.woo span#yes strong.no.yes i """ shouldCompileTo emblem, '
' suite "simple mustache" test "various one-liners", -> emblem = """ = foo arf p = foo span.foo p data-foo="yes" = goo """ shouldCompileTo emblem, { foo: "ASD", arf: "QWE", goo: "WER" }, 'ASDQWE
ASD
WER
' test "double =='s un-escape", -> emblem = """ == foo foo p == foo """ shouldCompileTo emblem, { foo: '123' }, '123<span>123</span>123
' test "nested combo syntax", -> emblem = """ ul = each items li = foo """ shouldCompileTo emblem, { items: [ { foo: "YEAH"}, { foo: "BOI" } ] }, 'Hello
Hello
Hello
Bracketed helper attrs!
View content
Yeah erp
' # TODO test overriding the default helper name (instead of always "view") suite "bang syntax defaults to `unbound` helper syntax" Handlebars.registerHelper 'unbound', -> options = arguments[arguments.length - 1] params = Array::slice.call arguments, 0, -1 stringedParams = params.join(' ') content = if options.fn then options.fn @ else stringedParams new Handlebars.SafeString """Yeah
' test "else works", -> emblem = """ foo? p Yeah else p No """ shouldCompileTo emblem, { foo: false }, 'No
' test "compound", -> emblem = """ p = foo? | Hooray else | No p = bar? | Hooray else | No """ shouldCompileTo emblem, { foo: true, bar: false }, 'Hooray
No
' test "compound", -> emblem = """ p = foo? bar else baz """ shouldCompileTo emblem, { foo: true, bar: "borf", baz: "narsty" }, 'borf
' suite "conditionals" test "simple if statement", -> emblem = """ if foo | Foo if bar | Bar """ shouldCompileTo emblem, {foo: true, bar: false}, 'Foo' test "if else ", -> emblem = """ if foo | Foo if bar | Bar else | Woot else | WRONG if bar | WRONG else | Hooray """ shouldCompileTo emblem, {foo: true, bar: false}, 'FooWootHooray' test "else with preceding `=`", -> emblem = """ = if foo p Yeah = else p No = if bar p Yeah! = else p No! =if bar p Yeah! =else p No! """ shouldCompileTo emblem, {foo: true, bar: false}, 'Yeah
No!
No!
' test "unless", -> emblem = """ unless bar | Foo unless foo | Bar else | Woot else | WRONG unless foo | WRONG else | Hooray """ shouldCompileTo emblem, {foo: true, bar: false}, 'FooWootHooray' test "else followed by newline doesn't gobble else content", -> emblem = """ if something p something else if nothing p nothing else p not nothing """ shouldCompileTo emblem, {}, 'not nothing
' suite "class shorthand and explicit declaration is coalesced" test "when literal class is used", -> shouldCompileTo 'p.foo class="bar"', '' test "when ember expression is used with variable", -> shouldCompileTo 'p.foo class=bar', {bar: 'baz'}, '' test "when ember expression is used with variable in braces", -> result = shouldEmberPrecompileToHelper 'p.foo class={ bar }' ok -1 != result.indexOf '\'class\': (":foo bar")' test "when ember expression is used with constant in braces", -> result = shouldEmberPrecompileToHelper 'p.foo class={ :bar }' ok -1 != result.indexOf '\'class\': (":foo :bar")' test "when ember expression is used with constant and variable in braces", -> result = shouldEmberPrecompileToHelper 'p.foo class={ :bar bar }' ok -1 != result.indexOf '\'class\': (":foo :bar bar")' test "when ember expression is used with bind-attr", -> result = shouldEmberPrecompileToHelper 'p.foo{ bind-attr class="bar" }' ok -1 != result.indexOf '\'class\': (":foo bar")' test "when ember expression is used with bind-attr and multiple attrs", -> result = shouldEmberPrecompileToHelper 'p.foo{ bind-attr something=bind class="bar" }' ok -1 != result.indexOf '\'class\': (":foo bar")' test "only with bind-attr helper", -> result = shouldEmberPrecompileToHelper 'p.foo{ someHelper class="bar" }', 'someHelper' ok -1 != result.indexOf '\'class\': ("bar")' ok -1 != result.indexOf 'class=\\"foo\\"' bindAttrHelper = -> options = arguments[arguments.length - 1] params = Array::slice.call arguments, 0, -1 bindingString = "" for own k,v of options.hash bindingString += " #{k} to #{v}" bindingString = " narf" unless bindingString param = params[0] || 'none' "bind-attr#{bindingString}" Handlebars.registerHelper 'bind-attr', bindAttrHelper EmberHandlebars.registerHelper 'bind-attr', bindAttrHelper suite "bind-attr behavior for unquoted attribute values" test "basic", -> emblem = 'p class=foo' shouldCompileTo emblem, {foo:"YEAH"}, '' shouldEmberPrecompileToHelper emblem test "basic w/ underscore", -> emblem = 'p class=foo_urns' shouldCompileTo emblem, {foo_urns: "YEAH"}, '' shouldEmberPrecompileToHelper emblem test "subproperties", -> emblem = 'p class=foo._death.woot' shouldCompileTo emblem, {foo: { _death: { woot: "YEAH" } }}, '' shouldEmberPrecompileToHelper emblem test "multiple", -> shouldCompileTo 'p class=foo id="yup" data-thinger=yeah Hooray', { foo: "FOO", yeah: "YEAH" }, 'Hooray
' test "class bind-attr special syntax", -> emblem = 'p class=foo:bar:baz' shouldEmberPrecompileToHelper emblem shouldThrow (-> CompilerContext.compile emblem) test "class bind-attr braced syntax w/ underscores and dashes", -> shouldEmberPrecompileToHelper 'p class={f-oo:bar :b_az}' shouldEmberPrecompileToHelper 'p class={ f-oo:bar :b_az }' shouldEmberPrecompileToHelper 'p class={ f-oo:bar :b_az } Hello' emblem = """ .input-prepend class={ filterOn:input-append } span.add-on """ shouldEmberPrecompileToHelper emblem test "exclamation modifier (vanilla)", -> emblem = 'p class=foo!' # exclamation is no-op in vanilla HB shouldCompileTo emblem, {foo:"YEAH"}, '' test "exclamation modifier (ember)", -> emblem = 'p class=foo!' result = precompileEmber emblem ok result.match /p class/ ok result.match /helpers\.unbound.*foo/ suite "in-tag explicit mustache" Handlebars.registerHelper 'inTagHelper', (p) -> return p; test "single", -> shouldCompileTo 'p{inTagHelper foo}', {foo: "ALEX"}, '' test "double", -> shouldCompileTo 'p{inTagHelper foo}', {foo: "ALEX"}, '' test "triple", -> shouldCompileTo 'p{inTagHelper foo}', {foo: "ALEX"}, '' Handlebars.registerHelper 'insertClass', (p) -> return 'class="' + p + '"' test "with singlestache", -> shouldCompileTo 'p{insertClass foo} Hello', {foo: "yar"}, 'Hello
' test "singlestache can be used in text nodes", -> shouldCompileTo 'p Hello {dork}', 'Hello {dork}
' test "with doublestache", -> shouldCompileTo 'p{{insertClass foo}} Hello', {foo: "yar"}, 'Hello
' test "with triplestache", -> shouldCompileTo 'p{{{insertClass foo}}} Hello', {foo: "yar"}, 'Hello
' test "multiple", -> shouldCompileTo 'p{{{insertClass foo}}}{{{insertClass boo}}} Hello', {foo: "yar", boo: "nar"}, 'Hello
' test "with nesting", -> emblem = """ p{{bind-attr class="foo"}} span Hello """ shouldCompileTo emblem, {foo: "yar"}, 'Hello
' suite "actions" Handlebars.registerHelper 'action', -> options = arguments[arguments.length - 1] params = Array::slice.call arguments, 0, -1 hashString = "" paramsString = params.join('|') # TODO: bad because it relies on hash ordering? # is this guaranteed? guess it doesn't rreeeeeally # matter since order's not being tested. for own k,v of options.hash hashString += " #{k}=#{v}" hashString = " nohash" unless hashString "action #{paramsString}#{hashString}" test "basic (click)", -> emblem = """ button click="submitComment" Submit Comment """ shouldCompileToString emblem, '' test "basic (click) followed by attr", -> emblem = """ button click="submitComment" class="foo" Submit Comment """ shouldCompileToString emblem, '' emblem = """ button click="submitComment 'omg'" class="foo" Submit Comment """ shouldCompileToString emblem, '' test "nested (mouseEnter)", -> emblem = """ a mouseEnter='submitComment target="view"' | Submit Comment """ shouldCompileToString emblem, 'Submit Comment' test "nested (mouseEnter, doublequoted)", -> emblem = """ a mouseEnter="submitComment target='view'" | Submit Comment """ shouldCompileToString emblem, 'Submit Comment' test "manual", -> emblem = """ a{action submitComment target="view"} Submit Comment """ shouldCompileToString emblem, 'Submit Comment' test "manual nested", -> emblem = """ a{action submitComment target="view"} p Submit Comment """ shouldCompileToString emblem, 'Submit Comment
' suite "haml style" test "basic", -> emblem = """ %borf """ shouldCompileToString emblem, 'Hello
LOL!
BORF!
Hello
' suite "old school handlebars" test "array", -> emblem = ''' goodbyes | #{text}! | cruel #{world}! ''' hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"} shouldCompileToString emblem, hash, "goodbye! Goodbye! GOODBYE! cruel world!" hash = {goodbyes: [], world: "world"} shouldCompileToString emblem, hash, "cruel world!" Handlebars.registerPartial('hbPartial', '{{name}}') test "calling handlebars partial", -> emblem = ''' > hbPartial | Hello #{> hbPartial} ''' shouldCompileToString emblem, { id: 666, name: "Death" }, 'DeathHello Death' Emblem.registerPartial(Handlebars, 'emblemPartial', 'a href="/people/{{id}}" = name') Emblem.registerPartial(Handlebars, 'emblemPartialB', 'p Grr') Emblem.registerPartial(Handlebars, 'emblemPartialC', 'p = a') test "calling emblem partial", -> shouldCompileToString '> emblemPartial', { id: 666, name: "Death" }, 'Death' test "calling emblem partial with context", -> shouldCompileToString '> emblemPartialC foo', { foo: { a: "YES" } }, 'YES
' test "partials in mustaches", -> emblem = """ | Hello, {{> emblemPartialC foo}}{{>emblemPartialB}}{{>emblemPartialB }} """ shouldCompileToString emblem, { foo: { a: "YES" } }, 'Hello,YES
Grr
Grr
' test "handlebars dot-separated paths with segment-literal notation", -> emblem = ''' p = articles.[3] ''' shouldCompileTo emblem, { articles: ['zero', 'one', 'two', 'three']}, 'three
' test "handlebars dot-separated paths with segment-literal notation, more nesting", -> emblem = ''' p = articles.[3].[#comments].[0] ''' shouldCompileTo emblem, { articles: [{}, {}, {}, {'#comments': ['bazinga']}]}, 'bazinga
' test "../path as inMustacheParam recognized correctly as pathIdNode instead of classShorthand", -> Handlebars.registerHelper 'jumpToParent', (link) -> new Handlebars.SafeString "Jump to parent top" emblem = ''' each children jumpToParent ../parentLink ''' shouldCompileTo emblem, {parentLink: '#anchor', children: [{}]}, 'Jump to parent top' test "block as #each", -> emblem = ''' thangs p Woot #{yeah} ''' shouldCompileToString emblem, { thangs: [{yeah: 123}, {yeah:456}] }, 'Woot 123
Woot 456
' if supportsEachHelperDataKeywords suite "each block helper keywords prefixed by @" test "#each with @index", -> emblem = ''' thangs p #{@index} Woot #{yeah} ''' shouldCompileToString emblem, { thangs: [{yeah: 123}, {yeah:456}] }, '0 Woot 123
1 Woot 456
' test "#each with @key", -> emblem = ''' each thangs p #{@key}: #{this} ''' shouldCompileTo emblem, { thangs: {'@key': 123, 'works!':456} }, '@key: 123
works!: 456
' test "#each with @key, @index", -> emblem = ''' each thangs p #{@index} #{@key}: #{this} ''' shouldCompileTo emblem, { thangs: {'@key': 123, 'works!':456} }, '0 @key: 123
1 works!: 456
' test "#each with @key, @first", -> emblem = ''' each thangs if @first p First item else p #{@key}: #{this} ''' shouldCompileTo emblem, { thangs: {'@key': 123, 'works!':456} }, 'First item
works!: 456
' ### test "partial in block", -> emblem = """ ul = people > link """ data = people: [ { "name": "Alan", "id": 1 } { "name": "Yehuda", "id": 2 } ] shouldCompileToString emblem, data, 'This be some text
This be some text
This be some text
This be some text
We design and develop ambitious web and mobile applications,
A more official portfolio page is on its way, but in the meantime, check out
We design and develop ambitious web and mobile applications,
A more official portfolio page is on its way, but in the meantime, check out
Alex
AlexEmily
Emily' suite "colon separator" test "basic", -> emblem = 'each foo: p Hello, #{this}' shouldCompileTo emblem, { foo: [ "Alex", "Emily", "Nicole" ] }, 'Hello, Alex
Hello, Emily
Hello, Nicole
' test "html stack", -> emblem = '.container: .row: .span5: span Hello' shouldCompileToString emblem, 'alex
This\n should\n hopefully\n work, and work well.\n' test "mixture", -> emblem = " \n" emblem += " p Hello\n" emblem += " p\n" emblem += " | Woot\n" emblem += " span yes\n" shouldCompileToString emblem, '
Hello
Woot
yes' test "mixture w/o opening blank", -> emblem = " p Hello\n" emblem += " p\n" emblem += " | Woot\n" emblem += " span yes\n" shouldCompileToString emblem, 'Hello
Woot
yes' test "w/ blank lines", -> emblem = " p Hello\n" emblem += " p\n" emblem += "\n" emblem += " | Woot\n" emblem += "\n" emblem += " span yes\n" shouldCompileToString emblem, 'Hello
Woot
yes' test "w/ blank whitespaced lines", -> emblem = " p Hello\n" emblem += " p\n" emblem += "\n" emblem += " | Woot\n" emblem += " \n" emblem += " \n" emblem += " \n" emblem += "\n" emblem += " span yes\n" emblem += "\n" emblem += " sally\n" emblem += "\n" emblem += " \n" emblem += " | Woot\n" shouldCompileToString emblem, 'Hello
Woot
yesHello, How are you?
I'm fine, thank you.
" suite "misc." test "end with indent", -> expect(0) return "PENDING" emblem = """ div p span Butts em fpokasd iunw paosdk """ shouldCompileToString emblem, 'Buttsem fpokasdiunw paosdk
Hello
' if supportsSubexpressions suite "subexpressions" Handlebars.registerHelper 'echo', (param) -> "ECHO #{param}" Handlebars.registerHelper 'echofun', -> options = Array.prototype.pop.call(arguments) "FUN = #{options.hash.fun}" Handlebars.registerHelper 'hello', (param) -> "hello" Handlebars.registerHelper 'equal', (x, y) -> x == y test "arg-less helper", -> emblem = 'p {{echo (hello)}}' shouldCompileTo emblem, 'ECHO hello
' emblem = '= echo (hello)' shouldCompileTo emblem, 'ECHO hello' test "helper w args", -> emblem = 'p {{echo (equal 1 1)}}' shouldCompileTo emblem, 'ECHO true
' emblem = '= echo (equal 1 1)' shouldCompileTo emblem, 'ECHO true' test "supports much nesting", -> emblem = 'p {{echo (equal (equal 1 1) true)}}' shouldCompileTo emblem, 'ECHO true
' emblem = '= echo (equal (equal 1 1) true)' shouldCompileTo emblem, 'ECHO true' test "with hashes", -> emblem = 'p {{echo (equal (equal 1 1) true fun="yes")}}' shouldCompileTo emblem, 'ECHO true
' emblem = '= echo (equal (equal 1 1) true fun="yes")' shouldCompileTo emblem, 'ECHO true' test "as hashes", -> emblem = 'p {{echofun fun=(equal 1 1)}}' shouldCompileTo emblem, 'FUN = true
' emblem = '= echofun fun=(equal 1 1)' shouldCompileTo emblem, 'FUN = true' test "complex expression", -> emblem = 'p {{echofun true (hello how="are" you=false) 1 not=true fun=(equal "ECHO hello" (echo (hello))) win="yes"}}' shouldCompileTo emblem, 'FUN = true
' emblem = '= echofun true (hello how="are" you=false) 1 not=true fun=(equal "ECHO hello" (echo (hello))) win="yes"' shouldCompileTo emblem, 'FUN = true'