모듈:Running header
보이기

이 모듈에 대한 설명문서를 생성할 수 있습니다. 연습장 (생성 | 복제) 및 시험장 (생성) 문서에서 이 모듈을 실험할 수 있습니다. 분류는 /설명문서 하위 문서에 넣어주세요. 이 모듈에 딸린 문서. |
--[=[
Implements [[Template:RunningHeader]]
]=]
require('strict')
local getArgs = require('Module:Arguments').getArgs
local p = {}
function p._running_header(args)
-- holds tracking categories
local tracking_cats = {}
-- aliases for first 3 parameters
if args.left or args.center or args.centre or args.right or args['왼쪽'] or args['가운데'] or args['오른쪽'] then
-- this is fine but it's worth keeping track of
table.insert(tracking_cats, '[[분류:' .. '변수 이름을 지정하고 있는 틀:난외표제' .. ']]')
-- check for duplicates (which are a problem)
if (args[1] and args.left) or (args[2] and args.center) or (args[2] and args.centre) or (args.center and args.centre) or (args[3] and args.right)
or (args[1] and args['왼쪽']) or (args[2] and args['가운데']) or (args['가운데'] and args.centre) or (args['가운데'] and args.centre) or (args[3] and args['오른쪽'])
or (args.left and args['왼쪽']) or (args.right and args['오른쪽'])
then
table.insert(tracking_cats, '[[분류:' .. '중복된 인수를 사용한 틀의 호출을 포함한 문서' .. ']]')
end
-- use aliases
args[1] = args[1] or args.left or args['왼쪽']
args[2] = args[2] or args.center or args.centre or args['가운데']
args[3] = args[3] or args.right or args['오른쪽']
end
-- get number of cells (largest-numbered parameter)
-- can't use #args because that doesn't work consistently on tables that aren't sequences
-- table.maxn also seems not to work
local cell_count = 0
for k, v in pairs(args) do
local i = tonumber(k)
if i and i > cell_count then
cell_count = i
end
end
-- track headers which don't set the contents of every cell
local undefined_entries = false
-- track how many cells have content
local content_entries = 0
for i = 1, cell_count do
if not args[i] then
undefined_entries = true
elseif args[i] and args[i] ~= '' then
content_entries = content_entries + 1
end
end
if undefined_entries then
-- track headers with undefined entries (fine but worth keeping track of)
table.insert(tracking_cats, '[[분류:' .. '정의되지 않은 항목을 사용한 틀:난외표제' .. ']]')
end
if content_entries == 1 then
-- track headers with only one non-blank entry
table.insert(tracking_cats, '[[분류:' .. '1개의 항목을 단독으로 사용한 틀:난외표제' .. ']]')
end
if cell_count == 0 or content_entries == 0 then
-- track headers with no entries (pointless)
table.insert(tracking_cats, '[[분류:' .. '비어 있는 틀:난외표제' .. ']]')
elseif cell_count == 1 then
-- track 1-cell headers (fine but worth keeping track of)
table.insert(tracking_cats, '[[분류:' .. '1개의 항목을 사용한 틀:난외표제' .. ']]')
elseif cell_count == 2 then
-- track 2-cell headers (fine but worth keeping track of)
table.insert(tracking_cats, '[[분류:' .. '2개의 항목을 사용한 틀:난외표제' .. ']]')
elseif cell_count > 4 then
-- track headers with more than 4 cells (fine but worth keeping track of)
table.insert(tracking_cats, '[[분류:' .. '4개 이상의 항목을 사용한 틀:난외표제' .. ']]')
end
-- TEMPORARY FOR MIGRATION: enforce 3-cell minimum
cell_count = math.max(cell_count, 3)
-- assemble cells
local cells = {}
-- classes
local base_class = 'wst-rh'
local cell_class = base_class .. '-cell'
local extra_cell_classes = {
[3] = {'wst-rh-left', 'wst-rh-center', 'wst-rh-right'}
}
extra_cell_classes = extra_cell_classes[cell_count] or {}
for i = 1, cell_count do
cells[i] = mw.html.create('div')
:addClass(cell_class)
:wikitext(args[i] or '')
if extra_cell_classes[i] then
cells[i]:addClass(extra_cell_classes[i])
end
cells[i] = tostring(cells[i])
end
-- assemble header
local header_class = table.concat({
base_class,
base_class .. '-' .. cell_count,
args.class or args['속성'] or (base_class .. '-default')
}, ' ')
local header_div = mw.html.create('div')
:addClass(header_class)
:wikitext(table.concat(cells))
return tostring(header_div) .. table.concat(tracking_cats)
end
function p.running_header(frame)
local args = getArgs(frame, {trim = true, removeBlanks = false})
return p._running_header(args)
end
return p