diff --git a/glass-dev-1.rockspec b/glass-dev-1.rockspec index 34135f6..418d182 100644 --- a/glass-dev-1.rockspec +++ b/glass-dev-1.rockspec @@ -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", diff --git a/glass/csv.lua b/glass/csv.lua new file mode 100644 index 0000000..4000fa2 --- /dev/null +++ b/glass/csv.lua @@ -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 diff --git a/readme.md b/readme.md index 8a25d2a..d86f659 100644 --- a/readme.md +++ b/readme.md @@ -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`)