Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Lyrics: Difference between revisions

From Sekaipedia
Content added Content deleted
No edit summary
mNo edit summary
Line 4: Line 4:


local p = {}
local p = {}

local columnOrderVariableKey = 'lyrics_column_order'




Line 10: Line 12:
local id = args['id'] or '1'
local id = args['id'] or '1'
local columnOrder = args['columnOrder']
local columnOrder = args['column order']
local columns = stringToArray(',')(columnOrder)
local columns = stringToArray(',')(columnOrder)
Line 27: Line 29:
end
end
VariablesLua.vardefine('lyrics_column_order', columnOrder)
VariablesLua.vardefine(columnOrderVariableKey, columnOrder)
return tostring(lyricsOptions) ..
return tostring(lyricsOptions) ..
string.format('<table class="wikitable" id="lyrics-%s">', id) ..
string.format('<table class="wikitable" id="lyrics-%s">', id) ..
Line 46: Line 48:
local root = mw.html.create('tr'):addClass('lyrics-row')
local root = mw.html.create('tr'):addClass('lyrics-row')
local columnOrder = VariablesLua.var('lyrics_column_order', '')
local columnOrder = VariablesLua.var(columnOrderVariableKey, '')
local columns = stringToArray(',')(columnOrder)
local columns = stringToArray(',')(columnOrder)

Revision as of 05:23, 14 April 2023

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

local getArgs   = require('Module:Arguments').getArgs
local stringToArray = require('Module:ProcessingFunctions').stringToArray
local VariablesLua = mw.ext.VariablesLua

local p = {}

local columnOrderVariableKey = 'lyrics_column_order'


function p.head(frame)
	local args = getArgs(frame)
	
	local id = args['id'] or '1'
	local columnOrder = args['column order']
	
	local columns = stringToArray(',')(columnOrder)
	
	local lyricsOptions = mw.html.create('div')
		:addClass('lyrics-options')
		:attr('data-id', id)
	
	local row = mw.html.create('tr'):addClass('lyrics-row')
	local columns = stringToArray(',')(columnOrder)
	for _,column in ipairs(columns) do
		root:tag('td')
			:addClass('lyrics-' .. column)
			:attr('width', math.floor(100 / #columns) .. '%')
			:wikitext(args[column])
	end
	
	VariablesLua.vardefine(columnOrderVariableKey, columnOrder)
	return tostring(lyricsOptions) ..
		string.format('<table class="wikitable" id="lyrics-%s">', id) ..
		tostring(row)
end

function p.line(frame)
	local function formatArg(arg)
		if arg and arg ~= '' then
			return table.concat(stringToArray('\n')(arg), '<br>')
		else
			return '<br>'
		end
	end

	local args = getArgs(frame)
	
	local root = mw.html.create('tr'):addClass('lyrics-row')
	
	local columnOrder = VariablesLua.var(columnOrderVariableKey, '')
	local columns = stringToArray(',')(columnOrder)
	
	for _,column in ipairs(columns) do
		
		root:tag('td')
			:addClass('lyrics-' .. column)
			:wikitext(formatArg(args[column])
		)
	end
	
	return tostring(root)
end

function p.tail(frame)
end

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