Skip to content

Commit

Permalink
Add helper support
Browse files Browse the repository at this point in the history
  • Loading branch information
sarenji committed Dec 12, 2011
1 parent 89d4107 commit d13f7c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/choco.coffee
Expand Up @@ -47,6 +47,7 @@ class ChocoContext
@buffer = []
@template = template
@locals = opts.locals or {}
@[name] = func for name, func of opts.helpers or {}

for element in elements.regular.concat elements.void
do (element) =>
Expand Down
12 changes: 11 additions & 1 deletion test/test.coffee
Expand Up @@ -91,4 +91,14 @@ describe 'a basic template', ->
@title "hello"
@body ->
@p "Hello world!"
output : '<!DOCTYPE html><html><head><title>hello</title></head><body><p>Hello world!</p></body></html>'
output : '<!DOCTYPE html><html><head><title>hello</title></head><body><p>Hello world!</p></body></html>'

describe 'a helper function', ->
it "gets included", test
render : ->
@js 'hullo.js'
opts:
helpers :
js : (url) ->
@script type: 'text/javascript', src: url
output : '<script type="text/javascript" src="hullo.js"></script>'

0 comments on commit d13f7c4

Please sign in to comment.