From 669b9d1ca8c07e169a9c0c15efe0674625d4d669 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Mon, 10 Jun 2013 15:54:42 -0700 Subject: [PATCH] Updated to expose an API that I *hope* integrates with ExpressJS. --- Makefile | 2 +- src/engine.coffee | 18 ++++++++++++++++++ src/{tumble.peg => lexer.peg} | 0 src/tumble.coffee | 10 ++++++++++ test/01_basics_mocha.coffee | 2 +- 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/engine.coffee rename src/{tumble.peg => lexer.peg} (100%) create mode 100644 src/tumble.coffee 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'))