local p =
function get_node (title) local title_data = mw.loadData("Module:Sandbox/KleptomaniacViolet/Language families/Data") local result = nil for n, page in pairs(title_data) do tab = mw.loadData(page).language_nodes if tab[title] ~= nil then result = tab[title] end end return resultend
function get_first_node_data (target_node_title, fallback_node_title, page_title, errors) if fallback_node_title ~= "" and page_title
local node_data = get_node(target_node_title) if node_data
nil then table.insert(errors, "no node data") else table.insert(errors, "using fallback") end end return node_dataend
function show_errors (frame, errors) local res = "" for i, err in ipairs(errors) do res = res .. "
" .. frame:expandTemplate end return resend
function p.gen_tree (frame) local errors = local target_node_title = frame.args["targetnode"] local expected_parent_article = frame.args["expectedparentarticle"] if expected_parent_article
local count = 0 while node_data ~= nil do display = node_data['display'] link = node_data['link'] if link ~= nil then wikitext = '' .. mw.text.nowiki(display) .. '' else wikitext = mw.text.nowiki(display) end table.insert(nodes, 1, wikitext) target_node_title = node_data['parent'] if target_node_title
nil then table.insert(errors, "no parent found but one was expected") elseif node_data['link'] ~= nil then if node_data['title'] ~= expected_parent_article then table.insert(errors, "expected parent mistmatch") end expected_parent_article = nil end end end end local result = "" for n, text in ipairs(nodes) do result = result .. '
function p.gen_children (frame) local errors = local target_node_title = frame.args["targetnode"] local fallback_node_title = frame.args["fallbacknode"] local page_title = frame.args["pagetitle"] local node_data = get_first_node_data(target_node_title, fallback_node_title, page_title, errors)
local child_titles = if node_data ~= nil then child_titles = node_data['children'] end local children = for n, child_title in ipairs(child_titles) do node_data = get_node(child_title) if node_data ~= nil then display = node_data['display'] link = node_data['link'] if link ~= nil then wikitext = '' .. mw.text.nowiki(display) .. '' else wikitext = mw.text.nowiki(display) end table.insert(children, 1, wikitext) end end local result = "" for n, text in ipairs(children) do result = result .. "* " .. text .. "\n" end return result .. "\n" .. show_errors(frame, errors)end
function p.get_parent_article (frame) local target_node_title = frame.args[1] local node_data = get_node(target_node_title) local res = nil local count = 0 while node_data ~= nil and res
nil then node_data = nil else node_data = get_node(node_data['parent']) end end if res
return p