Add csv reader using streamcsv

This commit is contained in:
Talia 2023-02-01 19:07:44 +01:00
parent 1a739d3af2
commit 51fd3673a0
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E
3 changed files with 17 additions and 0 deletions

View file

@ -15,6 +15,7 @@ build = {
modules = {
glass = "glass.lua",
["glass.cosmo"] = "glass/cosmo.lua",
["glass.csv"] = "glass/csv.lua",
["glass.discount"] = "glass/discount.lua",
["glass.environment"] = "glass/environment.lua",
["glass.error"] = "glass/error.lua",

15
glass/csv.lua Normal file
View file

@ -0,0 +1,15 @@
--- Loader for CSV-Data using streamcsv
-- @module glass.csv
local csv = require 'streamcsv'
--- Loads a CSV-File and returns a corresponding Lua table.
-- CSV file is assumed to have a header row.
-- @treturn table CSV-Data
-- @function load
return function(file)
local file = io.open(file..'.csv')
if file then
return csv.file(file)
end
end

View file

@ -28,6 +28,7 @@ A glass loader is initialised with a list of loaders and will try each of them i
## Loaders
Glass offers the following loaders out of the box:
* `cosmo` loads cosmo templates
* `csv` loads csv files (with header line)
* `discount` loads markdown files\*.
* `environment` loads environment variables.
* `json` loads a JSON file as a Lua table. (requires `cjson`)