Initial commit
This commit is contained in:
+34
@@ -0,0 +1,34 @@
|
||||
local yaml = require("yaml")
|
||||
local loader = {}
|
||||
loader.__index = loader
|
||||
|
||||
function loader:new(path_or_file)
|
||||
local c = {}
|
||||
setmetatable(c, loader)
|
||||
c.source = path_or_file
|
||||
local file = io.open(path_or_file .. "/index.yaml","r")
|
||||
if not file then
|
||||
error("Unable to load file: ".. path_or_file .."/index.yaml")
|
||||
end
|
||||
c.index = yaml.parse(file:read("*a"))
|
||||
for i,v in pairs(c.index.categories) do
|
||||
local link = io.open(path_or_file .. "/" .. v.name .. ".yaml")
|
||||
if not link then
|
||||
print("Error! Cannot find file: " .. path_or_file .."/" .. v.name .. ".yaml")
|
||||
else
|
||||
local category = yaml.parse(link:read("*a"))
|
||||
c.index.categories[i].questions = category.questions
|
||||
end
|
||||
end
|
||||
return c
|
||||
end
|
||||
|
||||
function loader:getCategories()
|
||||
return self.index.categories
|
||||
end
|
||||
|
||||
function loader:getSettings()
|
||||
return self.index.settings
|
||||
end
|
||||
|
||||
return loader
|
||||
Reference in New Issue
Block a user