Module:NavboxGenerator: Difference between revisions

Sur (talk | contribs)
m parametize data
Sur (talk | contribs)
m preprocess output for wikitext
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
local function generateNavbox(data, level)
local function generateNavbox(data, level)
     local result = {}
     local result = {}
     local boxSize = 5 - level  -- Adjust this to control the box size reduction per level
     local boxSizePercent = 100 - (level-1)*15 -- 15% less per level, 100%, 85%, 70%, 55%, etc.
     local fontSize = 150 - (level * 20)  -- Adjust to decrease font size per level
     local fontSize = 170 - (level * 15)  -- Adjust font size reduction per level
      
      
     for key, value in pairs(data) do
     for key, value in pairs(data) do
         if type(value) == "table" then
         if key == "Style" then
            -- Skip "Style" as it's just an attribute holder
        elseif key == "Display" then
            -- Leaf node, render Display content
             table.insert(result, string.format(
             table.insert(result, string.format(
                 '<div style="font-size:%d%%; border:1px solid #aaa; padding:5px; margin:2px;">=%s=</div>',
                 '<div style="text-align: center; font-size:%d%%;">%s</div>',
                 fontSize, key
                 fontSize, value
             ))
             ))
            table.insert(result, generateNavbox(value, level + 1)-- Recursively process next level
        elseif type(value) == "table" then
        else
            -- Nested node, render title with optional Style and recurse
             table.insert(result, string.format(
             table.insert(result, string.format(
                 '<div style="font-size:%d%%; padding-left:%dpx; margin:2px;">%s</div>',
                 '<div style="width: %s%%; margin-left: auto; margin-right: auto; text-align: center; font-size:%d%%; border:1px solid #aaa; %s">%s</div>',
                 fontSize, level * 10, value
                 boxSizePercent, fontSize, value.Style or "", key
             ))
             ))
            table.insert(result, generateNavbox(value, level + 1))  -- Recursively process next level
         end
         end
     end
     end
      
      
     return table.concat(result, "\n")
     return mw.getCurrentFrame():preprocess(table.concat(result, "\n"))
end
end