twitter / hogan.js

A compiler for the Mustache templating language
http://twitter.github.io/hogan.js
Apache License 2.0
5.14k stars 431 forks source link

inheritance doesn't work #244

Open kflu opened 8 years ago

kflu commented 8 years ago

The inheritance doesn't work as specified here.

Having three template files:

{{! header.mustache }}
<head>
  <title>{{$title}}Default title{{/title}}</title>
</head>
{{! base.mustache }}
<html>
  {{$header}}{{/header}}
  {{$content}}{{/content}}
</html>
{{! mypage.mustache }}
{{<base}}
  {{$header}}
    {{<header}}
      {{$title}}My page title{{/title}}
    {{/header}}
  {{/header}}

  {{$content}}
    <h1>Hello world</h1>
  {{/content}}
{{/base}}

Run hulk from the command line (something like this, you get the idea):

npm install hogan.js
cat "var Hogan = require('hogan.js');" > script.js
hulk *.mustache >> script.js
cat "templates['mypage'].render()" >> script.js

Run with node: node script.js. The rendered result is empty string.

I noticed that the in hulk compiled JS script, templates['mypage'] correctly references a partial called 'base':

> templates['base']
{ r: [Function],
  c: undefined,
  options: {},
  text: '',
  partials: {},
  subs: { header: [Function], content: [Function] },
  buf: '' }
>
> templates['header']
{ r: [Function],
  c: undefined,
  options: {},
  text: '',
  partials: {},
  subs: { title: [Function] },
  buf: '' }
>
> templates['mypage']
{ r: [Function],
  c: undefined,
  options: {},
  text: '',
  partials: { '<base11': { name: 'base1', partials: [Object], subs: [Object] } },
  subs: {},
  buf: '' }

But it seems there is still something missing to connect the dots.

node version: v5.6.0 hogan.js version: 3.0.2 hulk version: 3.0.2