Module:Navbox
Ir a la navegación
Ir a la búsqueda
Documentación La documentación a continuación se incluye desde Module:Navbox/doc. (editar | historial)
This module is invoked by the {{Navbox}} template. Navbox templates are not displayed for mobile users.
local p = {} local item = require('Module:Item').go local tr = require('Module:Tr') local strsub = string.sub local split = mw.text.split local trim = mw.text.trim local match = string.match local currentFrame local args local lang local l10n_table = { ["en"] = { title_v = "View this template", text_v = "V", title_d = "Discuss this template", text_d = "D", title_e = "Edit this template", text_e = "E", }, ["es"] = { title_v = "Ver esta plantilla", text_v = "v", title_d = "Discusión sobre esta plantilla", text_d = "d", title_e = "Editar esta plantilla", text_e = "e", }, } -- l10n local function l10n(key) if l10n_table[lang] then return l10n_table[lang][key] or l10n_table["en"][key] end return l10n_table["en"][key] end local function explode(div,str) if (div == '') then return false end local pos, arr = 0, {} for st,sp in function() return string.find(str, div, pos, true) end do arr[#arr + 1] = trim(string.sub(str, pos, st-1)) pos = sp + 1 end arr[#arr + 1] = trim(string.sub(str, pos)) return arr end local function returnLink(link) local frame = currentFrame local result = "" if match(link, "%[%[.*%]%]") or match(link, "%{%{.*%}%}") then return link else local result = {} -- "link|text&file#size" local text = link text, result["size"] = unpack(explode("%", text)) text, result["image"] = unpack(explode("&", text)) result[1], result[2] = unpack(explode("|", text)) if not result[2] or result[2] == "" then result[2] = tr.translate(trim(result[1]), 'es') end result["lang"] = lang return item(frame, result) end end local function renderList(list, header, paren) local result = "<div class=\"dotlist inline>" if header and header ~= "" then result = result .. "<span class=\"title\">" .. header .. "</span>" end result = result .. "<ul>" if paren then result = result .. "(" end local i = 1 while i <= #list do if type(list[i]) == "table" then result = result .. "<li>" .. renderList(list[i], nil, true) .. "</li>" elseif type(list[i + 1]) == "table" then result = result .. "<li>" .. returnLink(list[i]) .. ' ' .. renderList(list[i + 1], nil, true) .. "</li>" i = i + 1 else result = result .. "<li>" .. returnLink(list[i]) .. "</li>" end i = i + 1 end if paren then result = result .. ")" end result = result .. "</ul></div>" return result end local function renderH1(list) local result = "<div><div class=\"h1\">" .. list["h1"] .. "</div>" if list[1]["title"] then result = result .. "<div class=\"table\">" for i = 1, #list do result = result .. renderList(list[i], list[i]["title"], false) end result = result .. "</div>" else result = result .. renderList(list, "", false) end return result .. "</div>" end local function vde() if not args["template"] or args["template"] == "" then error("The template name is not defined!") end local result = {} result[1] = '[' .. tostring(mw.uri.fullUrl(mw.site.namespaces[10]["canonicalName"] .. ":" .. args["template"])) .. ' <span title="' .. l10n('title_v') .. '">' .. l10n('text_v') .. '</span>]' result[2] = '[' .. tostring(mw.uri.fullUrl(mw.site.namespaces[11]["canonicalName"] .. ":" .. args["template"])) .. ' <span title="' .. l10n('title_d') .. '">' .. l10n('text_d') .. '</span>]' result[3] = '[' .. tostring(mw.uri.fullUrl(mw.site.namespaces[828]["canonicalName"] .. ":Navbox/" .. args[1], "action=edit")) .. ' <span title="' .. l10n('title_e') .. '">' .. l10n('text_e') .. '</span>]' return '<div class="vde plainlinks">' .. table.concat(result, ' • ') .. '</div>' end local function renderHeader(list, isMain) local collapsed = "mw-collapsed" if (args[list["__metadata"]] and args[list["__metadata"]] ~= "") or (args["all"] and args["all"] ~= "") then collapsed = "" end local result = "<div class=\"navbox mw-collapsible " .. collapsed .. ">" if isMain then result = result .. vde() end if list["header"] and list["header"] ~= "" then result = result .. "<div class=\"navheader\">" .. list["header"] .. "</div>" end result = result .. "<div class=\"content mw-collapsible-content\">" if not list[1]["header"] then result = result .. "<div class=\"table\">" end for i = 1, #list do if list[i]["header"] then result = result .. renderHeader(list[i], false) elseif list[i]["h1"] then result = result .. renderH1(list[i]) else result = result .. renderList(list, nil, false) break end end if not list[1]["header"] then result = result .. "</div>" end result = result .. "</div></div>" return result end function p.main(frame) currentFrame = frame args = frame:getParent().args lang = frame:expandTemplate{ title = "lang"} local data = require("Module:Navbox/" .. args[1]) return frame:preprocess(renderHeader(data, true)) end return p