Skip to content

Commit

Permalink
Add csv reader using streamcsv
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkWiiPlayer committed Feb 1, 2023
1 parent 1a739d3 commit 51fd367
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions glass-dev-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions glass/csv.lua
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down

0 comments on commit 51fd367

Please # to comment.