Add csv reader using streamcsv
This commit is contained in:
parent
1a739d3af2
commit
51fd3673a0
3 changed files with 17 additions and 0 deletions
|
@ -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
15
glass/csv.lua
Normal 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
|
|
@ -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`)
|
||||
|
|
Loading…
Reference in a new issue