return false, err.new("no config file available")
end
---- Create a extensions config.
-function e2lib.write_extension_config(extensions)
- local e = err.new("writing extensions config: %s", e2lib.globals.extension_config)
- local f, re = io.open(e2lib.globals.extension_config, "w")
- if not f then
- return false, e:cat(re)
- end
- f:write(string.format("extensions {\n"))
- for _,ex in ipairs(extensions) do
- f:write(string.format(" {\n"))
- for k,v in pairs(ex) do
- f:write(string.format(" %s=\"%s\",\n", k, v))
- end
- f:write(string.format(" },\n"))
- end
- f:write(string.format("}\n"))
- f:close()
- return true, nil
-end
-
--- read the local extension configuration
-- This function must run while being located in the projects root directory
-- @return the extension configuration table
local e2option = require("e2option")
local buildconfig = require("buildconfig")
+--- Create a extensions config.
+-- @param extensions Table.
+-- @return True on success, false on error.
+-- @return Error object on failure.
+local function write_extension_config(extensions)
+ local e, rc, re, file, out
+
+ e = err.new("writing extensions config: %s", e2lib.globals.extension_config)
+ file, re = eio.fopen(e2lib.globals.extension_config, "w")
+ if not file then
+ return false, e:cat(re)
+ end
+
+ out = "extensions {\n"
+ for _,ex in ipairs(extensions) do
+ out = out .. " {\n"
+ for k,v in pairs(ex) do
+ out = out .. string.format(" %s=\"%s\",\n", k, v)
+ end
+ out = out .. " },\n"
+ end
+ out = out .. "}\n"
+
+ rc, re = eio.fwrite(file, out)
+ if not rc then
+ return false, e:cat(re)
+ end
+
+ rc, re = eio.fclose(file)
+ if not rc then
+ return false, e:cat(re)
+ end
+
+ return true
+end
+
--- Read a template file, located relative to the current template directory.
-- @param path Filename relative to the template directory.
-- @return File contents as a string, or false on error.
return false, e:cat(re)
end
end
- rc, re = e2lib.write_extension_config(config.site.default_extensions)
+ rc, re = write_extension_config(config.site.default_extensions)
if not rc then
return false, e:cat(re)
end