「モジュール:Toolbar」を編集中
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
1行目: | 1行目: | ||
local p = {} | local p = {} | ||
+ | local args = {} | ||
− | + | -- Get the keys of the numerical arguments that are present. | |
− | + | local function getArgNums() | |
− | + | local nums = {} | |
− | + | for k, v in pairs(args) do | |
− | + | if type(k) == 'number' then | |
− | + | table.insert(nums, k) | |
− | + | end | |
− | + | end | |
− | + | table.sort(nums) | |
− | + | return nums | |
− | |||
end | end | ||
− | local function makeToolbarItems( | + | local function makeToolbarItems() |
− | + | -- Get numerical argument keys. | |
− | + | local nums = getArgNums() | |
− | + | -- Get the separator text. | |
− | + | local sep = (args.separator or 'pipe') .. '-separator' | |
− | + | sep = mw.message.new(sep):plain() | |
− | + | ||
− | + | -- Generate the toolbar items. | |
− | + | local ret = '' | |
− | + | for i, v in ipairs(nums) do | |
− | + | ret = ret .. args[v] | |
− | + | if nums[i + 1] then | |
+ | ret = ret .. sep | ||
+ | end | ||
+ | end | ||
+ | return ret | ||
end | end | ||
− | function | + | local function makeToolbar() |
− | + | local class = (args.class and (' ' .. args.class)) or '' | |
− | + | local style = (args.style and (' style="' .. args.style .. '"')) or '' | |
− | + | ||
− | + | local ret = '<span class="plainlinks' .. class .. '"' .. style .. '>' | |
− | + | .. '(' .. makeToolbarItems() .. ')' | |
− | + | .. '</span>' | |
− | + | ||
− | + | return ret | |
end | end | ||
function p.main(frame) | function p.main(frame) | ||
− | + | -- If called via #invoke, use the args passed into the invoking template. | |
− | + | -- Otherwise, for testing purposes, assume args are being passed directly in. | |
− | + | local origArgs | |
− | + | if frame == mw.getCurrentFrame() then | |
− | + | origArgs = frame:getParent().args | |
− | + | else | |
− | + | origArgs = frame | |
− | + | end | |
− | + | ||
− | + | -- Strip whitespace and remove nil values | |
− | + | for k, v in pairs(origArgs) do | |
− | + | v = mw.text.trim(v) | |
− | + | if v ~= '' then | |
− | + | args[k] = v | |
− | + | end | |
− | + | end | |
− | + | ||
− | + | return makeToolbar() | |
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | ||
return p | return p |