UNPKG

hem-render-html

Version:

This module adds the ability to dynamically generate HTML files for your hem project.

49 lines (38 loc) 1.1 kB
Hem = require('hem') fs = require('fs') html = require('./html') path = require('path') class HemRenderHtml extends Hem htmlOptions: html: './html' htmlDelete: on htmlGlobalContextFile: '__global.coffee' htmlPath: './public' constructor: (options = {}) -> @htmlOptions[key] = value for key, value of options super @htmlOptions server: -> @watchHtml() super build: -> @buildHtml() super buildHtml: -> if path.existsSync(@options.html) @htmlPackage().compile() watch: -> @watchHtml() super watchHtml: -> @buildHtml() dir = path.dirname(@options.html) dir = @options.html if path.existsSync(dir) require('watch').watchTree dir, (file, curr, prev) => if curr and (curr.nlink is 0 or +curr.mtime isnt +prev?.mtime) console.log "#{file} changed. Rebuilding all HTML files." @buildHtml() htmlPackage: -> html.createPackage(@options.html, @options.htmlPath, @options.htmlDelete, @options.htmlGlobalContextFile) module.exports = HemRenderHtml