Module:Ref: Difference between revisions

From Halopedia, the Halo wiki

No edit summary
No edit summary
Line 5: Line 5:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


--[[[
Constructs a reference with the given text, using the provided parser frame, ref
id and group.
@param object frame The current parser frame
@param string id The id to give to the reference
@param string group The group to include the reference in
@param string text The text of the reference
@return the constructed reference
]]
function makeRef( frame, id, group, text )
function makeRef( frame, id, group, text )
if text == nil or text == '' then
if utils.empty( text ) then
return utils.error(
return utils.error(
'No reference text was specified!',
'No reference text was specified!',
Line 14: Line 25:
text = tostring( text )
text = tostring( text )
local args = {}
local args = {}
if id ~= nil and id ~= '' then
if not utils.empty( id ) then
args.name = tostring( id )
args.name = tostring( id )
end
end
if group ~= nil and group ~= '' then
if not utils.empty( group ) then
args.group = tostring( group )
args.group = tostring( group )
end
end
Line 25: Line 36:


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


Line 52: Line 63:
return frame:extensionTag( 'references', '', args )
return frame:extensionTag( 'references', '', args )
end
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

Revision as of 15:43, December 15, 2021

vde
Lua Module Documentation

This module provides the backend implementations of the Ref templates.

Public Functions

ref.ref

ref.list

ref.generic

Private Functions

makeRef

Constructs a reference with the given text, using the provided parser frame, ref id and group.

Parameters:

  • object frame The current parser frame - nil
  • string id The id to give to the reference - nil
  • string group The group to include the reference in - nil
  • string text The text of the reference - nil

Returns:

' - the constructed reference

makeGenericRef

makeReuse

makeList

Code

A copy of the code for this module follows:


local utils = require( 'Module:Utils' )

--------------------------------------------------------------------------------
------------------------------- PRIVATE FUNCTIONS ------------------------------
--------------------------------------------------------------------------------

--[[[
Constructs a reference with the given text, using the provided parser frame, ref
id and group.

@param object frame The current parser frame
@param string id The id to give to the reference
@param string group The group to include the reference in
@param string text The text of the reference

@return the constructed reference
]]
function makeRef( frame, id, group, text )
	if utils.empty( text ) then
		return utils.error(
			'No reference text was specified!',
			'ref',
			'Pages with empty citations' )
	end
	text = tostring( text )
	local args = {}
	if not utils.empty( id ) then
		args.name = tostring( id )
	end
	if not utils.empty( group ) then
		args.group = tostring( group )
	end
	
	return frame:extensionTag( 'ref', text, args )
end

function makeGenericRef( frame, id, group )
	return makeRef( frame, id, group, text )
end

function makeReuse( frame, id, group )
	local args = {}
	if id == nil or id == '' then
		return utils.error(
			'No id was specified for ref reuse!',
			'ref',
			'Pages containing missing template parameter errors' )
	else
		args.name = tostring( id )
	end
	if group ~= nil and group ~= '' then
		args.group = tostring( group )
	end
	return frame:extensionTag( 'ref', '', args )
end

function makeList( frame, id, group )
	local args = {}
	if group ~= nil and group ~= '' then
		args.group = tostring( group )
	end
	
	return frame:extensionTag( 'references', '', args )
end

--------------------------------------------------------------------------------
------------------------------- PUBLIC FUNCTIONS -------------------------------
--------------------------------------------------------------------------------

local ref = {}

function ref.ref( frame )
	local templateFrame = frame:getParent()
	local id = templateFrame.args['Id'] or templateFrame.args['Name']
	local group = templateFrame.args['Group']
	local text = templateFrame.args[1] or templateFrame.args['Text']
	return makeRef( frame, text, id, group )
end

function ref.list( frame )
	local templateFrame = frame:getParent()
	local group = templateFrame.args['Group']
	return makeList( frame, group, colNum, colWidth, colGap )
end

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

return ref