CoffeeKup: Add Class to Elements

CoffeeKup is a very succinct and flexible templating engine to define HTML documents in a less verbose manner. It is based on CoffeeScript.

Unfortunately, the documentation of CoffeeKup I could find was not very clear on how to perform one of the most basic tasks in creating HTML documents:

How do I assign a class to an element?

And here is the answer:

div class: 'myclass', ->

  div class: 'nested'

Which will result in the HTML document:

<div class='myclass'>

  <div class='nested'></div>

</div>

Or in more succinct form:

div 'myclass', ->

  div 'nested', ->

Please note the ‘->’ after the declaration of the class for the second div. Without it, CoffeeKup would render ‘nested’ as text and not as element.

Resources

CoffeeKup Reference

CoffeeKup Login Example

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s