🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

thermos

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thermos

Easy HTML templating in pure CoffeeScript

0.1.0
latest
Source
npm
Version published
Maintainers
2
Created
Source

thermos Build Status

thermos is a templating engine that lets you write HTML templates in CoffeeScript.

It's a branch of CoffeeMugg, a branch of CoffeeKup.

Usage

thermos = require 'thermos'

thermos.render ->
  @doctype 5
  @html ->
    @head ->
      @title "hello"
      @js "main"
    @body ->
      @p "Hello world!"

HTML entities

HTML entities are automatically encoded for you. Writing this:

thermos.render ->
  @h1 ->
    @span '<b>—&</b>"\'&mdash;hi'

will produce <h1><span>&gt;b&lt;&mdash;&amp;&gt;/b&lt;&quot;&apos;&mdash;hi</span></h1>

You can use @html_safe to prevent Thermos from auto-encoding entities for you. For example, @span @html_safe '<b>—&</b>"\'' will output <h1><span><b>—&</b>"\'</span></h1>.

Extending thermos

Configuration

thermos = require 'thermos'

thermos.configure
  helpers :
    header_link : (text, url) ->
      @h1 ->
        @link_to text, url

thermos.render ->
  @doctype 5
  @html ->
    @head ->
      @title "hello"
      @js "main"
    @body ->
      @header_link "Hello world!", "/"
      @div "#content"
        @p "foobar"

Passing options

thermos = require 'thermos'

options =
  helpers :
    header_link : (text, url) ->
      @h1 ->
        @link_to text, url

thermos.render options, ->
  @doctype 5
  @html ->
    @head ->
      @title "hello"
      @js "main"
    @body ->
      @header_link "Hello world!", "/"
      @div "#content"
        @p "foobar"

Default helpers

Currently, thermos includes @js, @css, and @link_to helpers by default.

@link_to text, url
@js url
@css url

@link_to "click here", "#anchor"
@link_to "click here", "http://example.com"
@link_to "click here", "/about"

@js "jquery"
@js "jquery.min"
@js "jquery.min.js"
@js "/vendor/jquery.min"
@js "/vendor/jquery.min.js"
@js "http://example.com/jquery"
@js "http://example.com/jquery.js"

@css "main"
@css "main.css"
# same as @js

Why thermos?

CoffeeKup breaks closures. Extending CoffeeMugg isn't as nice as I'd like.

Test

thermos uses mocha for running tests.

$ npm install
$ mocha

Installation

$ npm install thermos

Thanks to

jaekwon, for CoffeeMugg. mauricemach, for CoffeeKup.

Don't kill me, both.

Keywords

template

FAQs

Package last updated on 28 Aug 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts