Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 751dcbbb9d
Fetching contributors…

Cannot retrieve contributors at this time

153 lines (94 sloc) 3.101 kb

Purpose

Connect Hogan.js with Express, with support for Partials.

Hi {{name}}

{{> salute}}

Why is Hogan.js Awesome?

Logic-less templates, keeping control separate from views. Views separated from content.

Doesn't have many bells and whistles. HTML Structure, and views are suppose to be simple.

Mustache is awesome. Has many implementations. It's clear what's a {{variable}} and what is not.

Why Hulk-Hogan?

Becaues he's awesome. But also because there wasn't a solution I could find that let's you easily use Mustaches' partials natively with Express.

Partials Example

body.hulk

  {{> header}}
  My body.
  {{> footer}}

header.hulk

<h1>Hey There</h1>

footer.hulk

<footer>See ya</footer>

Produces:

  <h1>Hey There</h1>
  My body.
  <footer>See ya</footer>

Sub-Partials supported

You can link partials from within other partials.

  main.hulk

  {{>body}}

  body.hulk

  {{>header}}
  {{>footer}}

Usage Example

views/index.hulk

Hello {{what}}!

CoffeScript

app.coffee

  express = require 'express'
  hulk = require 'hulk-hogan'

  app = express.createServer()

  app.set 'views', __dirname+'/views'  # Directory of your views
  app.set 'view options', layout:false
  app.set 'view engine', 'hulk'  # use the .hulk file extensions for your views
  app.register '.hulk', hulk  # register to render .hulk with Hulk-Hogan

  app.get '/', (req,res)->
    res.render 'index', {what:'World'}

  app.listen 3000

coffee app.coffee http://localhost:3000 would produce:

Hello World!

JavaScript

app.js

 var app, express, hulk;

 express = require('express');
 hulk = require('hulk-hogan');

 app = express.createServer();

 app.set('views', __dirname + '/views');
 app.set('view options', {layout: false});
 app.set('view engine', 'hulk');
 app.register('.hulk', hulk);

 app.get('/', function(req, res) {
   res.render('index', {
     what: 'World'
   });
 });

 app.listen(3000); 

node app.js http://localhost:3000 would produce:

Hello World!

Automated Tests

Hulk-Hogan uses mocha & mocha-cakes for testing.

make buffet should run all tests.

Thanks

Hulk-Hogan inspired by HBS

should checkout express-hogan.js

and Micah Smith's hogan-express.js blog post for reference.


Special Thanks to the Hogan.js Twitter Team, as well as Hulk-Hogan's grand-dad, (or is it more like Great Uncle?) Mustache.

Also Thanks to TJ for the excellent Express and Express-Resource.

Jump to Line
Something went wrong with that request. Please try again.