Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var sys = require('sys')
- var fs = require('fs')
- var http = require('http')
- var haml = require('hamljs');
- var exec = require('child_process').exec
- var argv = process.argv
- var target = argv[2]
- var parser = argv[3] || 'ruby'
- if(!target){
- console.error('usage: ' + argv.join(' ') + ' <filename>')
- process.exit(1)
- }
- fs.stat(target, function(e, stat){
- if(e){ throw e }
- if(!stat.isFile()) {
- console.error(target + ' is not file.')
- process.exit(1)
- }
- fs.watchFile(target, { interval: 500 }, function(curr, prev){
- Parser[parser](target)
- })
- })
- var Parser = {
- ruby: function(target){
- var output = target.replace('.haml', '.html'),
- cmd = 'haml -f html5 --trace ' + target + ' ' + output
- exec(cmd, function (e, stdout, stderr) {
- if(e){ console.error(e) }
- console.log('updated ', output)
- })
- },
- hamljs: function(target){
- fs.readFile(target, 'utf8', function (e, text) {
- if(e){ throw e }
- try{
- var html = haml.render(text)
- var output = target.replace('.haml', '.html')
- fs.writeFile(output, html, function(e){
- if(e){ throw e }
- console.log('updated ', output)
- })
- }catch(e){
- console.error(e)
- }
- })
- }
- }
Add Comment
Please, Sign In to add comment