Module:Track list: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
mNo edit summary
Line 15: Line 15:
return {
return {
['col'] = col,
['col'] = col,
['idx'] = tonumber(idx)
['idx'] = idx
}
}
-- end
-- end
Line 33: Line 33:
x = x .. ',' .. mw.text.jsonEncode(col_idx)
x = x .. ',' .. mw.text.jsonEncode(col_idx)
if col_idx then
-- if col_idx then
local col = col_idx['col']
-- local col = col_idx['col']
local idx = col_idx['idx']
-- local idx = col_idx['idx']
rows[idx][col] = v
-- rows[idx][col] = v
end
-- end
end
end

Revision as of 06:40, 17 October 2021

Documentation for this module may be created at Module:Track list/doc

local getArgs   = require('Module:Arguments').getArgs

local p = {}

local function extract(str)
	local col = nil
	local title_col = string.find(str, "^title%d$")
	local singer_col = string.find(str, "^singer%d$")
	local length_col = string.find(str, "^length%d$")
	local idx = string.find(str, "^%d$")
	
	col = title_col or singer_col or length_col
	
	-- if col and idx then
		return {
			['col'] = col,
			['idx'] = idx
		}
	-- end
	
	-- return nil
end

function p.main(frame)
	local x = ''
	
	local args = getArgs(frame)
	local rows = {}
	local root = mw.html.create()
	
	for k,v in pairs(args) do
		local col_idx = extract(k)
		x = x .. ',' .. mw.text.jsonEncode(col_idx)
		
		-- if col_idx then
		-- 	local col = col_idx['col']
		-- 	local idx = col_idx['idx']
		-- 	rows[idx][col] = v
		-- end
	end
	
	local root_table = root:tag('table')
		:addClass('wikitable')
		:css({
			['margin-bottom'] = 0
		})
		:tag('tr')
			:tag('th'):wikitext('No.'):done()
			:tag('th'):wikitext('Title'):done()
			:tag('th'):wikitext('Singer(s)'):done()
			:tag('th'):wikitext('Length'):done()
			:done()
			
	-- for k,v in pairs(rows) do
	-- 	local no = k
	-- 	local title = v['title']
	-- 	local singer = v['singer']
	-- 	local length = v['length']
		
	-- 	root_table:tag('tr')
	-- 		:tag('th'):wikitext('1'):done()
	-- 		:tag('td'):wikitext(title):done()
	-- 		:tag('td'):wikitext(singer):done()
	-- 		:tag('td')
	-- 			:css({
	-- 				['text-align'] = 'center'
	-- 			})
	-- 			:wikitext(length)
	-- 			:done()
	-- end
	
	root_table:tag('tr')
		:tag('th')
			:attr('colspan', 3)
			:css({
				['text-align'] = 'right'
			})
			:wikitext('Total length:')
			:done()
		:tag('th')
			:wikitext()
			:done()
	
	root:tag('sup')
			:wikitext('[[Template:Track List|View]] • [[Template talk:Track List|Talk]]')
			:done()
		:done()
	
	return tostring(root) .. x
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.