Add fennel loader
This commit is contained in:
parent
89b53d1aa2
commit
f99667fbf5
4 changed files with 30 additions and 1 deletions
5
.busted
5
.busted
|
@ -1,5 +1,8 @@
|
||||||
return {
|
return {
|
||||||
_all = {
|
_all = {
|
||||||
lpath = "?.lua;?/init.lua"
|
lpath = "?.lua;?/init.lua"
|
||||||
}
|
};
|
||||||
|
core = {
|
||||||
|
recursive = false
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
18
glass/fennel.lua
Normal file
18
glass/fennel.lua
Normal file
|
@ -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
|
6
spec/fennel/fennel_loader_spec.moon
Normal file
6
spec/fennel/fennel_loader_spec.moon
Normal file
|
@ -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
|
2
spec/fixtures/test.fnl
vendored
Normal file
2
spec/fixtures/test.fnl
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
{"foo" "bar"
|
||||||
|
"tab" []}
|
Loading…
Reference in a new issue