Module:Navbox: Difference between revisions
ReisuDesign (talk | contribs) Created page with "-- version 1.2.5 -- config table for RANGER. -- If you want to change the default config, DO NOT change it here, -- please do it via the `onLoadConfig` hook in Module:Navbox/Hooks. local config = { default_navbox_class = "navigation-not-searchable", -- Base value of the `class` parameter. default_title_class = nil, -- Base value of the `title_class` parameter. default_above_class = nil, -- Base value of the `above_class` parameter. default_below_class =..." |
ReisuDesign (talk | contribs) No edit summary |
||
| (3 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
-- version 1.2.5 | -- Source: https://defaultloadout.wiki.gg/wiki/Module:Navbox | ||
-- version 1.2.5.1 | |||
-- config table for RANGER. | -- config table for RANGER. | ||
| Line 5: | Line 6: | ||
-- please do it via the `onLoadConfig` hook in [[Module:Navbox/Hooks]]. | -- please do it via the `onLoadConfig` hook in [[Module:Navbox/Hooks]]. | ||
local config = { | local config = { | ||
default_navbox_class = "navigation-not-searchable", -- Base value of the `class` parameter. | default_navbox_class = "navigation-not-searchable noexcerpt", -- Base value of the `class` parameter. | ||
default_title_class = nil, -- Base value of the `title_class` parameter. | default_title_class = nil, -- Base value of the `title_class` parameter. | ||
default_above_class = nil, -- Base value of the `above_class` parameter. | default_above_class = nil, -- Base value of the `above_class` parameter. | ||
| Line 135: | Line 136: | ||
args = h.parseArgs(args) | args = h.parseArgs(args) | ||
end | end | ||
args = h.expandAutomaticGroups(args) | |||
h.runHook('onLoadConfig', config, args) | h.runHook('onLoadConfig', config, args) | ||
| Line 293: | Line 296: | ||
-- parse arguments, convert them to structured data tree | -- parse arguments, convert them to structured data tree | ||
-- Expand automatic group markers | |||
function h.expandAutomaticGroups(args) | |||
local PREFIX = '__NAVBOX_AUTO_GROUPS__' | |||
local value = args.automatic_groups | |||
if type(value) ~= 'string' or value:sub(1, #PREFIX) ~= PREFIX then | |||
return args | |||
end | |||
local payload = value:sub(#PREFIX + 1) | |||
local ok, data = pcall(mw.text.jsonDecode, payload) | |||
if not ok or type(data) ~= 'table' or type(data.rows) ~= 'table' then | |||
error('Invalid Navbox Automatic Groups data.') | |||
end | |||
local index = tonumber(data.start) or 1 | |||
if index < 1 or index % 1 ~= 0 then | |||
error('Invalid Navbox Automatic Groups start index.') | |||
end | |||
for _, row in ipairs(data.rows) do | |||
local groupKey = index .. ':group' | |||
local listKey = index .. ':list' | |||
if args[groupKey] ~= nil or args[listKey] ~= nil then | |||
error('Navbox Automatic Groups overlaps an existing row at index ' .. index .. '.') | |||
end | |||
if row.group ~= nil and row.group ~= '' then | |||
args[groupKey] = row.group | |||
end | |||
if row.list ~= nil then | |||
args[listKey] = row.list | |||
end | |||
index = index + 1 | |||
end | |||
args.automatic_groups = nil | |||
return args | |||
end | |||
function h.buildDataTree(args) | function h.buildDataTree(args) | ||
-- parse args to a tree | -- parse args to a tree | ||
| Line 564: | Line 612: | ||
:wikitext(data.below.content) | :wikitext(data.below.content) | ||
end | end | ||
return tostring(out) | return tostring(out) | ||
end | end | ||