Skip to content

Commit

Permalink
Convert to promises, add header footer
Browse files Browse the repository at this point in the history
  • Loading branch information
danielr-minted committed Mar 17, 2015
1 parent 5d5e38d commit 664525c
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 195 deletions.
3 changes: 2 additions & 1 deletion bin/templito
@@ -1,3 +1,4 @@
#!/usr/bin/env node
require('coffee-script');
var CoffeeScript = require('coffee-script');
CoffeeScript.register();
require('../templito-cli');
2 changes: 1 addition & 1 deletion bin/test
@@ -1,3 +1,3 @@
#!/bin/bash

bin/templito test/templates test/compiled_templates $@
bin/templito -H test/header.js -F test/footer.js test/templates test/compiled_templates $@
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -30,12 +30,13 @@
"author": "Paul Harper <benekastah@gmail.com>",
"license": "BSD",
"dependencies": {
"coffee-script": "~1.9.1",
"optimist": "~0.4.0",
"coffee-script": "~1.6.2"
"q": "^1.2.0"
},
"optionalDependencies": {
"underscore": "~1.4.4",
"node-watch": "~0.3.3"
"underscore": "~1.8.2",
"node-watch": "~0.3.4"
},
"preferGlobal": true
}
24 changes: 17 additions & 7 deletions templito-cli.coffee
Expand Up @@ -4,6 +4,7 @@ watch = require 'node-watch'
log = require('./utilities').log
templito = require './'

# TODO remove optimist. it's deprecated
argv = require('optimist')
.usage('Compiles underscore.js templates into javascript files.\n\n' +
'templito source-dir out-dir [options]')
Expand All @@ -15,9 +16,9 @@ argv = require('optimist')
'file).'
default: 'directory'
p:
alias: 'path-case'
alias: "path-case"
describe: 'The casing for the object path part of an output ' +
'function\'s address. If the template is ' +
"function's address. If the template is " +
'source_dir/a/b/c.html, then the object path part is ' +
'source_dir/a/b. Options include "camelCase", "CapitalCase", ' +
' and "snake_case".'
Expand Down Expand Up @@ -61,6 +62,12 @@ argv = require('optimist')
describe: 'Provide a function to pass the compiled template to. ' +
'Useful if you need to process the result of an underscore ' +
'template function call for any reason.'
F:
alias: 'footer'
describe: 'A file to append as a footer'
H:
alias: 'header'
describe: 'A file to append as a header'
).argv

show_help = (msg) ->
Expand All @@ -80,7 +87,7 @@ for key, value of argv

if argv.template_settings?
try
argv.template_settings = eval("(#{argv.template_settings});")
argv.template_settings = eval "#{argv.template_settings};"
catch e
console.error "The template-settings you passed in " +
"(#{argv.template_settings}) does not appear to be a " +
Expand All @@ -98,11 +105,14 @@ timeout = null
timeout_duration = 500
compile = ->
log 'Trying to compile templates...'
result = templito.compile argv, ->
templito.compile argv
.then () ->
log 'Done.'
if not result
log "Compile job in progress."
timeout_compile()
.catch (err) ->
log err
if err.stack
log err.stack
throw err
compile()

timeout_compile = ->
Expand Down

0 comments on commit 664525c

Please sign in to comment.