index.js 1.16 KB
Newer Older
1
2
3
#!/usr/bin/env node
var hogan = require('hogan.js')
  , fs    = require('fs')
4
  , prod  = process.argv[2] == 'production'
5
  , title = 'Bootstrap'
6
7
8
9
10

var layout, pages

// compile layout template
layout = fs.readFileSync(__dirname + '/../templates/layout.mustache', 'utf-8')
11
layout = hogan.compile(layout, { sectionTags: [{o:'_i', c:'i'}] })
12
13
14
15
16
17
18

// retrieve pages
pages = fs.readdirSync(__dirname + '/../templates/pages')

// iterate over pages
pages.forEach(function (name) {

Jacob Thornton's avatar
Jacob Thornton committed
19
  if (!name.match(/\.mustache$/)) return
Jacob Thornton's avatar
Jacob Thornton committed
20

21
22
23
24
  var page = fs.readFileSync(__dirname  + '/../templates/pages/' + name, 'utf-8')
    , context = {}

  context[name.replace(/\.mustache$/, '')] = 'active'
25
  context._i = true
26
  context.production = prod
27
28
29
30
31
32
33
34
35
36
  context.title = name
    .replace(/\.mustache/, '')
    .replace(/\-.*/, '')
    .replace(/(.)/, function ($1) { return $1.toUpperCase() })

  if (context.title == 'Index') {
    context.title = title
  } else {
    context.title += ' · ' + title
  }
37
38

  page = hogan.compile(page, { sectionTags: [{o:'_i', c:'i'}] })
39
40
41
42
43
44
  page = layout.render(context, {
    body: page
  })

  fs.writeFileSync(__dirname + '/../' + name.replace(/mustache$/, 'html'), page, 'utf-8')
})