diff --git a/Makefile b/Makefile index 4f9b7ed..c8b5cea 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ lib: $(cof_objects): $(cof_sources) @mkdir -p $(@D) - $(COFFEE) -o $(@D) -c $< + $(foreach source, $(cof_sources), $(COFFEE) -o $(@D) -c $(source); ) $(peg_objects): $(peg_sources) @mkdir -p $(@D) diff --git a/src/engine.coffee b/src/engine.coffee new file mode 100644 index 0000000..67d8f8c --- /dev/null +++ b/src/engine.coffee @@ -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 diff --git a/src/tumble.peg b/src/lexer.peg similarity index 100% rename from src/tumble.peg rename to src/lexer.peg diff --git a/src/tumble.coffee b/src/tumble.coffee new file mode 100644 index 0000000..d8186c6 --- /dev/null +++ b/src/tumble.coffee @@ -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 +} \ No newline at end of file diff --git a/test/01_basics_mocha.coffee b/test/01_basics_mocha.coffee index 21ed741..e670910 100644 --- a/test/01_basics_mocha.coffee +++ b/test/01_basics_mocha.coffee @@ -6,7 +6,7 @@ util = require 'util' fs = require 'fs' path = require 'path' -tumble = require('../lib/tumble').parse; +tumble = require('../lib/lexer').parse; parse = require('../lib/parser'); test_data = JSON.parse(fs.readFileSync(path.join(__dirname, 'data.json'), 'utf-8'))