diff --git a/.busted b/.busted index bf887f6..5d1b48a 100644 --- a/.busted +++ b/.busted @@ -1,5 +1,8 @@ return { _all = { lpath = "?.lua;?/init.lua" - } + }; + core = { + recursive = false + }; } diff --git a/glass/fennel.lua b/glass/fennel.lua new file mode 100644 index 0000000..630dc27 --- /dev/null +++ b/glass/fennel.lua @@ -0,0 +1,18 @@ +--- Loader for Fennel files +-- @module glass.fennel + +local fennel = require "fennel" +local read = require 'glass.raw' + +--- Loads and compiles a Fennel file and runs it. +-- Returns the result of running the Fennel file. +-- If running the code immediately is not desired, +-- it has to be returned as a function. +-- @return The result of the Fennel file after running it +-- @function load +return function(file) + local success, raw = read(file..'.fnl') + if success then + return true, fennel.eval(raw) + end +end diff --git a/spec/fennel/fennel_loader_spec.moon b/spec/fennel/fennel_loader_spec.moon new file mode 100644 index 0000000..5f802a8 --- /dev/null +++ b/spec/fennel/fennel_loader_spec.moon @@ -0,0 +1,6 @@ +describe 'fennel loader', -> + before_each -> export loader = require 'glass.fennel' + it 'loads Fennel files', -> + success, result = loader 'spec/fixtures/test' + assert.true success + assert.same { foo: 'bar', tab: {} }, result diff --git a/spec/fixtures/test.fnl b/spec/fixtures/test.fnl new file mode 100644 index 0000000..9b70311 --- /dev/null +++ b/spec/fixtures/test.fnl @@ -0,0 +1,2 @@ +{"foo" "bar" + "tab" []}