Module:Ref: Difference between revisions

From Halopedia, the Halo wiki

No edit summary
No edit summary
Line 1: Line 1:
local utils = require( 'Module:Utils' )
local utils = require( 'Module:Utils' )


local p = {}
local ref = {}


function ref( text, id, group )
function makeRef( text, id, group )
if text == nil or text == '' then
if text == nil or text == '' then
return utils.error( 'No reference text was specified!', 'ref', 'Pages with empty citations' )
return utils.error(
'No reference text was specified!',
'ref',
'Pages with empty citations' )
end
end
text = tostring( text )
text = tostring( text )
Line 19: Line 22:
end
end


function p.ref( frame )
function makeGenericRef( id, group )
local text = frame.args[1]
return 'TODO: Implement this'
end
 
function makeList( group, colNum, colWidth, colGap )
local warnings = ''
local listArgs = {}
if group ~= nil and group ~= '' then
listArgs.group = tostring( group )
end
local divArgs = {}
if colNum ~= nil and colNum ~= '' then
if tonumber( colNum ) == nil then
warnings = warnings .. utils.warning(
'Column amount must be a number! Instead, it was: "' .. colNum .. '"!',
'ref list',
'Pages containing invalid template parameter warnings' )
else
colNum = tonumber( colNum )
divArgs[ '-moz-column-count' ] = colNum
divArgs[ '-moz-webkit-count' ] = colNum
divArgs[ 'column-count' ] = colNum
end
end
if colWidth ~= nil and colWidth ~= '' then
colWidth = tostring( colWidth )
if string.find( colWidth, '[:;"\']') then
warnings = warnings .. utils.warning(
'Column width cannot contain any of the following characters: \' " ; :',
'ref list',
'Pages containing invalid template parameter warnings' )
else
divArgs[ '-moz-column-width' ] = colWidth
divArgs[ '-webkit-column-width' ] = colWidth
divArgs[ 'column-width' ] = colWidth
end
end
if colGap ~= nil and colGap ~= '' then
colGap = tostring( colGap )
if string.find( colGap, '[:;"\']') then
warnings = warnings .. utils.warning(
'Column gap cannot contain any of the following characters: \' " ; :',
'ref list',
'Pages containing invalid template parameter warnings' )
else
divArgs[ '-moz-column-gap' ] = colGap
divArgs[ '-webkit-column-gap' ] = colGap
divArgs[ 'column-gap' ] = colGap
end
end
local wikitext = frame:extensionTag( 'references', '', listArgs )
local html = mw.html.create( 'div' )
:attr( divArgs )
:wikitext( wikitext )
:allDone()
return html .. warnings
end
 
function ref.ref( frame )
local id = frame.args[2]
local id = frame.args[2]
local group = frame.args[3]
local group = frame.args[3]
return ref( text, id, group )
local text = frame.args[1]
return makeRef( text, id, group )
end
 
function ref.generic( frame )
return 'TODO: Implement this'
end
end


return p
return p

Revision as of 16:15, April 25, 2021

vde
Lua Module Documentation

This module provides the backend implementations of the Ref templates.

Private Functions

makeRef

makeGenericRef

makeList

ref.ref

ref.generic

Code

A copy of the code for this module follows:


local utils = require( 'Module:Utils' )

local ref = {}

function makeRef( text, id, group )
	if text == nil or text == '' then
		return utils.error(
			'No reference text was specified!',
			'ref',
			'Pages with empty citations' )
	end
	text = tostring( text )
	local args = {}
	if id ~= nil and id ~= '' then
		args.name = tostring( id )
	end
	if group ~= nil and group ~= '' then
		args.group = tostring( group )
	end
	local frame = mw.getCurrentFrame()
	return frame:extensionTag( 'ref', text, args )
end

function makeGenericRef( id, group )
	return 'TODO: Implement this'
end

function makeList( group, colNum, colWidth, colGap )
	local warnings = ''
	
	local listArgs = {}
	if group ~= nil and group ~= '' then
		listArgs.group = tostring( group )
	end
	
	local divArgs = {}
	if colNum ~= nil and colNum ~= '' then
		if tonumber( colNum ) == nil then
			warnings = warnings .. utils.warning(
				'Column amount must be a number! Instead, it was: "' .. colNum .. '"!',
				'ref list',
				'Pages containing invalid template parameter warnings' )
		else
			colNum = tonumber( colNum )
			divArgs[ '-moz-column-count' ] = colNum
			divArgs[ '-moz-webkit-count' ] = colNum
			divArgs[ 'column-count' ] = colNum
		end
	end
	if colWidth ~= nil and colWidth ~= '' then
		colWidth = tostring( colWidth )
		if string.find( colWidth, '[:;"\']') then
			warnings = warnings .. utils.warning(
				'Column width cannot contain any of the following characters: \' " ; :',
				'ref list',
				'Pages containing invalid template parameter warnings' )
		else
			divArgs[ '-moz-column-width' ] = colWidth
			divArgs[ '-webkit-column-width' ] = colWidth
			divArgs[ 'column-width' ] = colWidth
		end
	end
	if colGap ~= nil and colGap ~= '' then
		colGap = tostring( colGap )
		if string.find( colGap, '[:;"\']') then
			warnings = warnings .. utils.warning(
				'Column gap cannot contain any of the following characters: \' " ; :',
				'ref list',
				'Pages containing invalid template parameter warnings' )
		else
			divArgs[ '-moz-column-gap' ] = colGap
			divArgs[ '-webkit-column-gap' ] = colGap
			divArgs[ 'column-gap' ] = colGap
		end
	end
	
	local wikitext = frame:extensionTag( 'references', '', listArgs )
	local html = mw.html.create( 'div' )
		:attr( divArgs )
		:wikitext( wikitext )
		:allDone()
	
	return html .. warnings
end

function ref.ref( frame )
	local id = frame.args[2]
	local group = frame.args[3]
	local text = frame.args[1]
	return makeRef( text, id, group )
end

function ref.generic( frame )
	return 'TODO: Implement this'
end

return p