You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey @pwnall -- make sure you have toffee 0.1.3 and any of these examples should work:
toffee=require'toffee'# ----------------------------------# An example, using a view# ----------------------------------v=newtoffee.view''' Dear #{name}, Here be some odd numbers: #{(x for x in [1...20] by 2).join ', '}'''
[err, res] =v.run {name:"Chris"}
console.log res
Note that the view can take an optional second parameter with your autoescape, etc., settings, as mentioned in the documentation. It can also take a "fileName" var which helps with debugging.
Alternatively, for convenience, you can create the view and return its run function in one swoop, with the convenience function compileStr:
# ------------------------------------------------# An example using the convenience function compileStr# ------------------------------------------------fn=toffee.compileStr'Hi there, #{name}'
[err, res] =fn {name:'Bob'}
If you want to use your own partial function, you can.
# ------------------------------------------------# An example, using your own partial function + a view# ------------------------------------------------v=newtoffee.view'Hi there, #{name}. Check out #{partial "foo.toffee", {age:212} }'
[err, res] =v.run {
name:"Batman"partial: (fname, vars) ->"\n\nTODO: implement partials so I can print #{fname} / #{vars}"
}
And again, you can use the compileStr convenience function if you prefer:
# ------------------------------------------------# An example, using your own partial function + compileStr# ------------------------------------------------fn=toffee.compileStr'Hi there, #{name}. Check out #{partial "foo.toffee", {age:22} }'
[err, res] =fn {
name:'George Bluth'partial: (fname, vars) ->"\n\nTODO: implement partials so I can print #{fname} / #{vars}"
}
Activity
malgorithms commentedon Jul 1, 2013
Hey @pwnall -- make sure you have toffee 0.1.3 and any of these examples should work:
Note that the view can take an optional second parameter with your autoescape, etc., settings, as mentioned in the documentation. It can also take a "fileName" var which helps with debugging.
Alternatively, for convenience, you can create the view and return its run function in one swoop, with the convenience function
compileStr:If you want to use your own partial function, you can.
And again, you can use the
compileStrconvenience function if you prefer:Let me know if this answers your question...
-Chris