local export = {}
local m_links = require("Module:links")
local m_languages = require("Module:languages")
local function format_list_items(items, lang)
local result = {}
for i, item in ipairs(items) do
if lang and not string.find(item, "<span") then
item = m_links.full_link({lang = lang, term = item})
end
result = '\n* ' .. item
end
return table.concat(result)
end
local collapse_header =
]
local column_header = ]
.. ]
.. ]
local button = ]
.. ]
.. ]
function export.create_list(args)
-- Fields in args that are used:
-- args.column_count, args.content, args.alphabetize, args.background_color,
-- args.collapse, args.toggle_category, args.class, args.lang
-- Check for required fields?
if type(args) ~= "table" then
error("expected table, got " .. type(args))
end
args.class = args.class or "derivedterms"
args.column_count = args.column_count or 1
args.toggle_category = args.toggle_category or "derived terms"
local output = {}
if args.header then
table.insert(output, args.header)
end
if args.collapse then
table.insert(output, (collapse_header:gsub('{{{(.-)}}}', args)))
table.insert(output, button)
end
table.insert(output, (column_header:gsub('{{{(.-)}}}', args)))
if args.alphabetize then
require("Module:collation").sort(args.content, args.lang)
end
table.insert(output, format_list_items(args.content, args.lang))
table.insert(output, '</div>')
if args.collapse then
table.insert(output, '</div>')
end
return table.concat(output)
end
-- This function is for compatibility with earlier version of ]
-- (now found in ]).
function export.create_table(...)
-- Earlier arguments to create_table:
-- n_columns, content, alphabetize, bg, collapse, class, title, column_width, line_start, lang
local args = {}
args.column_count, args.content, args.alphabetize, args.background_color,
args.collapse, args.class, args.title, args.column_width,
args.line_start, args.lang = ...
return export.create_list(args)
end
function export.display(frame)
local params = {
= {},
= {type = "boolean"},
= {type = "number"},
= {},
= {type = "boolean"},
= {default = ""},
= {},
}
local frame_args = require("Module:parameters").process(frame.args, params)
params = {
= {list = true},
= {},
= not frame_args and {required = true, default = "und"} or nil,
= {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local lang = frame_args or args
lang = m_languages.getByCode(lang) or m_languages.err(lang, "lang")
local header
if args then
header = '<div class="term-list-header">' .. args .. "</div>"
end
return export.create_list { column_count = frame_args,
content = args, alphabetize = frame_args,
header = header, background_color = "#F8F8FF",
collapse = frame_args,
toggle_category = frame_args,
class = frame_args, lang = lang, }
end
return export