Updated to expose an API that I *hope* integrates with ExpressJS.

This commit is contained in:
Elf M. Sternberg 2013-06-10 15:54:42 -07:00
parent 047b64a60f
commit 669b9d1ca8
5 changed files with 30 additions and 2 deletions

View File

@ -22,7 +22,7 @@ lib:
$(cof_objects): $(cof_sources) $(cof_objects): $(cof_sources)
@mkdir -p $(@D) @mkdir -p $(@D)
$(COFFEE) -o $(@D) -c $< $(foreach source, $(cof_sources), $(COFFEE) -o $(@D) -c $(source); )
$(peg_objects): $(peg_sources) $(peg_objects): $(peg_sources)
@mkdir -p $(@D) @mkdir -p $(@D)

18
src/engine.coffee Normal file
View File

@ -0,0 +1,18 @@
tumble = require('./lexer').parse;
parse = require('./parser');
fs = require 'fs'
render = (str, options, callback) ->
try
callback(null, parse(tumble(str), options))
catch err
callback(err, null)
fromFile = (path, options, callback) ->
fs.readFile path, 'utf8', (err, str) ->
return callback(err) if err
render(str, options, callback)
fromFile.render = render
exports = fromFile

10
src/tumble.coffee Normal file
View File

@ -0,0 +1,10 @@
lexer = require './lexer'
parse = require './parser'
engine = require './engine'
module.exports = {
tumble: lexer.parse,
parse: parse,
render: (str, data) -> parse(lexer.parse(str), data)
engine: engine
}

View File

@ -6,7 +6,7 @@ util = require 'util'
fs = require 'fs' fs = require 'fs'
path = require 'path' path = require 'path'
tumble = require('../lib/tumble').parse; tumble = require('../lib/lexer').parse;
parse = require('../lib/parser'); parse = require('../lib/parser');
test_data = JSON.parse(fs.readFileSync(path.join(__dirname, 'data.json'), 'utf-8')) test_data = JSON.parse(fs.readFileSync(path.join(__dirname, 'data.json'), 'utf-8'))