Module:Miscellaneous
Overview
Module for implementing various templates in lua that are not big/complex enough to warrent their own module.
List of currently implemented templates
The above documentation is transcluded from Module:Miscellaneous/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
--[[
Module for implementing miscellaneous templates in lua.
Mostly exists here so we don't have hundred of module pages for templates that don't have a lot of code.
If a template requires a *lot* of coding consider moving it into it's own lua module.
]]--
local xtable = require('Module:Table')
local util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs
local m_item = require('Module:Item')
local p = {}
local g_frame, g_args
--
-- Template: ItemFilterList
--
function p.filter_list(frame)
g_args = getArgs(frame, {
parentFirst = true
})
if frame == nil or type(frame) == 'table' then
frame = mw.getCurrentFrame()
end
tbl = mw.html.create('table')
tbl
:attr('class', 'wikitable sortable')
:tag('tr')
:tag('th')
:attr('rowspan', 2)
:wikitext('Name')
:done()
:tag('th')
:attr('rowspan', 2)
:wikitext('Author')
:done()
:tag('th')
:attr('rowspan', 2)
:wikitext('Direct Link')
:done()
:tag('th')
:attr('colspan', 8)
:wikitext('Features')
:done()
:tag('th')
:attr('rowspan', 2)
:wikitext('Release')
:done()
:done()
:tag('tr')
:tag('th')
:wikitext('Colours')
:done()
:tag('th')
:wikitext('Borders')
:done()
:tag('th')
:wikitext('Font<br>Size')
:done()
:tag('th')
:wikitext('Item<br>Hiding')
:done()
:tag('th')
:wikitext('Leveling')
:done()
:tag('th')
:wikitext('Endgame')
:done()
:tag('th')
:wikitext('Vendor<br>recipes')
:done()
:tag('th')
:wikitext('Crafting')
:done()
:done()
:wikitext(g_args.rows)
return tostring(tbl) .. frame:extensionTag{ name = 'references', content = '', args = {group='note'}}
end
--
-- Template: ItemFilterListRow
--
local filter_list_required_args = xtable:new({'name', 'release_link', 'author', 'direct_link', 'colour', 'border', 'font_size', 'item_hiding', 'leveling', 'endgame', 'vendor_recipes', 'crafting', 'release'})
local filter_list_yes_no_args = xtable:new({'colour', 'border', 'font_size', 'item_hiding'})
local filter_list_yes_no = xtable:new({'yes', 'no'})
local filter_list_yes_no_partial_args = xtable:new({'leveling', 'endgame', 'vendor_recipes', 'crafting'})
local filter_list_yes_no_partial = xtable:new({'yes', 'no', 'partial'})
-- Test: =p.filter_list_row{name='a', release_link='http://google.de', author='Mario', author_contact='No idea', direct_link='http://google.de', colour='yes', border='yes', font_size='no', item_hiding='yes', leveling='partial', endgame='yes', vendor_recipes='partial', crafting='no', release='2015'}
function p.filter_list_row(frame)
g_args = getArgs(frame, {
parentFirst = true
})
if frame == nil or type(frame) == 'table' then
frame = mw.getCurrentFrame()
end
-- Checking args
for _, arg in ipairs(filter_list_required_args) do
if g_args[arg] == nil then
error('Required argument ' .. arg .. ' is missing')
end
end
for _, arg in ipairs(filter_list_yes_no_args) do
local val = g_args[arg]
if not filter_list_yes_no:contains(val) then
error('Argument ' .. args .. ' requires one of the following arguments: ' .. table.concat(filter_list_yesno))
end
end
for _, arg in ipairs(filter_list_yes_no_partial_args) do
local val = g_args[arg]
if not filter_list_yes_no_partial:contains(val) then
error('Argument ' .. args .. ' requires one of the following arguments: ' .. table.concat(filter_list_yesno))
end
end
-- Output
tblrow = mw.html.create('tr')
tblrow
:tag('td')
:wikitext('[' .. g_args.release_link .. ' ' .. g_args.name .. ']')
:done()
:tag('td')
:wikitext(g_args.author)
:done()
:tag('td')
:wikitext(g_args.direct_link)
:done()
for _, arg in ipairs(filter_list_yes_no_args) do
tblrow
:tag('td')
:attr('class', 'table-cell-' .. g_args[arg])
:wikitext(g_args[arg])
:done()
end
for _, arg in ipairs(filter_list_yes_no_partial_args) do
local note = g_args[arg .. '_note']
local ref = ''
if note ~= nil then
ref = frame:extensionTag{ name = 'ref', content = note, args = {group='note'}}
end
tblrow
:tag('td')
:attr('class', 'table-cell-' .. g_args[arg])
:wikitext(g_args[arg] .. ref)
:done()
end
tblrow
:tag('td')
:wikitext(g_args.release)
:done()
return tostring(tblrow)
end
return p