(hoofbeats) Migrates to Tizen 2.0 'content' webapi.
[profile/ivi/cowhide.git] / docs / build / index.js
1 #!/usr/bin/env node
2 var hogan = require('hogan.js')
3   , fs    = require('fs')
4   , prod  = process.argv[2] == 'production'
5   , title = 'Cowhide'
6
7 var layout, pages
8
9 // compile layout template
10 layout = fs.readFileSync(__dirname + '/../templates/layout.mustache', 'utf-8')
11 layout = hogan.compile(layout, { sectionTags: [{o:'_i', c:'i'}] })
12
13 // retrieve pages
14 pages = fs.readdirSync(__dirname + '/../templates/pages')
15
16 // iterate over pages
17 pages.forEach(function (name) {
18
19   if (!name.match(/\.mustache$/)) return
20
21   var page = fs.readFileSync(__dirname  + '/../templates/pages/' + name, 'utf-8')
22     , context = {}
23
24   context[name.replace(/\.mustache$/, '')] = 'active'
25   context._i = true
26   context.production = prod
27   context.title = name
28     .replace(/\.mustache/, '')
29     .replace(/\-.*/, '')
30     .replace(/(.)/, function ($1) { return $1.toUpperCase() })
31
32   if (context.title == 'Index') {
33     context.title = title
34   } else {
35     context.title += ' ยท ' + title
36   }
37
38   page = hogan.compile(page, { sectionTags: [{o:'_i', c:'i'}] })
39   page = layout.render(context, {
40     body: page
41   })
42
43   fs.writeFileSync(__dirname + '/../' + name.replace(/mustache$/, 'html'), page, 'utf-8')
44 })