mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 23:33:53 +01:00
Schema: Generate Markdown & format Readme
This commit is contained in:
parent
5f748d37d8
commit
5399a0f302
16
mod.lua
16
mod.lua
@ -100,6 +100,22 @@ function configuration(modname)
|
|||||||
conf = schema:load(overrides, {convert_strings = true, error_message = true})
|
conf = schema:load(overrides, {convert_strings = true, error_message = true})
|
||||||
end
|
end
|
||||||
modlib.file.ensure_content(get_resource(modname, "settingtypes.txt"), schema:generate_settingtypes())
|
modlib.file.ensure_content(get_resource(modname, "settingtypes.txt"), schema:generate_settingtypes())
|
||||||
|
local readme_path = get_resource(modname, "Readme.md")
|
||||||
|
local readme = modlib.file.read(readme_path)
|
||||||
|
if readme then
|
||||||
|
local modified = false
|
||||||
|
readme = readme:gsub("<!%-%-modlib:conf:(%d)%-%->" .. "(.-)" .. "<!%-%-modlib:conf%-%->", function(level, content)
|
||||||
|
schema._md_level = assert(tonumber(level)) + 1
|
||||||
|
local markdown = schema:generate_markdown()
|
||||||
|
if content ~= markdown then
|
||||||
|
modified = true
|
||||||
|
return "<!--modlib:conf:" .. level .. "-->" .. markdown .. "<!--modlib:conf-->"
|
||||||
|
end
|
||||||
|
end, 1)
|
||||||
|
if modified then
|
||||||
|
assert(modlib.file.write(readme_path, readme))
|
||||||
|
end
|
||||||
|
end
|
||||||
if conf == nil then
|
if conf == nil then
|
||||||
return schema:load({}, {error_message = true})
|
return schema:load({}, {error_message = true})
|
||||||
end
|
end
|
||||||
|
@ -77,7 +77,7 @@ function generate_markdown(self)
|
|||||||
-- TODO address redundancies
|
-- TODO address redundancies
|
||||||
local typ = self.type
|
local typ = self.type
|
||||||
self.title = self.title or field_name_to_title(self._md_name)
|
self.title = self.title or field_name_to_title(self._md_name)
|
||||||
self._level = self._level or 1
|
self._md_level = self._md_level or 1
|
||||||
if typ == "table" then
|
if typ == "table" then
|
||||||
local handled = {}
|
local handled = {}
|
||||||
local settings = {}
|
local settings = {}
|
||||||
@ -88,8 +88,8 @@ function generate_markdown(self)
|
|||||||
handled[key] = true
|
handled[key] = true
|
||||||
value_scheme._md_name = key
|
value_scheme._md_name = key
|
||||||
value_scheme.title = value_scheme.title or self.title .. " " .. field_name_to_title(key)
|
value_scheme.title = value_scheme.title or self.title .. " " .. field_name_to_title(key)
|
||||||
value_scheme._level = self._level + 1
|
value_scheme._md_level = self._md_level + 1
|
||||||
table.insert(settings, table.concat(modlib.table.repetition("#", self._level)) .. " `" .. key .. "`")
|
table.insert(settings, table.concat(modlib.table.repetition("#", self._md_level)) .. " `" .. key .. "`")
|
||||||
table.insert(settings, generate_markdown(value_scheme))
|
table.insert(settings, generate_markdown(value_scheme))
|
||||||
table.insert(settings, "")
|
table.insert(settings, "")
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user