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 arguments = require( 'Module:Arguments' ) | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
Line 156: | Line 157: | ||
]] | ]] | ||
function ref.generic( frame ) | function ref.generic( frame ) | ||
local args, out = arguments.preprocess( frame, { | |||
[ 'valid' ] = { 'id', 'subheading', 3, 4, 5, 6, 7, 'detail', 'quote', | |||
'quotee', 'quoteelinktext', 'suffix' }, | |||
[ 'recommended' ] = { 2 }, | |||
[ 'required' ] = { 'heading' }, | |||
[ 'aliases' ] = { [ 1 ] = 'heading' } | |||
}) | |||
return out .. args.heading | |||
end | end | ||
return ref | return ref |
Revision as of 12:55, December 27, 2021
This module provides the backend implementations of the Ref templates.
Public Functions
ref.ref
Invocation entry point for Template:Ref. Takes arguments Id, Name, Group and Text from the template parser frame and constructs the appropriate reference.
Parameters:
- frame (object) - The current parser frame
Returns:
wikitext - the constructed reference
ref.list
Invocation entry point for Template:Ref/List. Takes argument Group from the template parser frame and constructs the appropriate reference list.
Parameters:
- frame (object) - The current parser frame
Returns:
wikitext - the constructed reference list
ref.generic
Invocation entry point for Template:Ref/Generic. Currently unimplemented.
Parameters:
- frame (object) - The current parser frame
Returns:
wikitext - the constructed reference
Private Functions
makeRef
Constructs a reference with the given text, using the provided parser frame, ref id and group.
Parameters:
- frame (object) - The current parser frame
- id (string) - The id to give to the reference
- group (string) - The group to include the reference in
- text (string) - The text of the reference
Returns:
wikitext - the constructed reference
makeStandardRef
Constructs a standard format reference using the given parameters, with the provided content. Content table supports unlimited numeric arguments, in addition to Section, Detail, Quote, Quotee and Suffix arguments.
Parameters:
- frame (object) - The current parser frame
- id (string) - The id to give to the reference
- group (string) - The group to include the reference in
- content (table) - The content of the reference
Returns:
wikitext - the constructed reference
makeRefText
Generates the text content of a standard format reference from the provided arguments. Content table supports unlimited numeric arguments, in addition to Section, Detail, Quote, Quotee and Suffix arguments.
Parameters:
- content (table) - The content of the reference
Returns:
wikitext - the constructed reference text
makeReuse
Constructs wikitext to reuse an existing reference with the given id, in the given group.
Parameters:
- frame (object) - The current parser frame
- id (string) - The id to give to the reference
- group (string) - The group to include the reference in
Returns:
wikitext - the constructed reference reuse wikitext
makeList
Constructs the list of references in a given group.
Parameters:
- frame (object) - The current parser frame
- group (string) - The reference group to list
- colNum (int) - The number of columns to use in the list
- colWidth (int) - The width list columns should be
- colGap (int) - The size of the gap between list columns
Returns:
wikitext - the constructed reference
Code
A copy of the code for this module follows:
local utils = require( 'Module:Utils' )
local arguments = require( 'Module:Arguments' )
--------------------------------------------------------------------------------
------------------------------- PRIVATE FUNCTIONS ------------------------------
--------------------------------------------------------------------------------
--[[[
Constructs a reference with the given text, using the provided parser frame, ref
id and group.
@param frame - object - The current parser frame
@param id - string - The id to give to the reference
@param group - string - The group to include the reference in
@param text - string - The text of the reference
@return wikitext - 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
--[[[
Constructs a standard format reference using the given parameters, with the
provided content. Content table supports unlimited numeric arguments, in
addition to Section, Detail, Quote, Quotee and Suffix arguments.
@param frame - object - The current parser frame
@param id - string - The id to give to the reference
@param group - string - The group to include the reference in
@param content - table - The content of the reference
@return wikitext - the constructed reference
]]
function makeStandardRef( frame, id, group, content )
local text = makeRefText( content )
return makeRef( frame, id, group, text )
end
--[[[
Generates the text content of a standard format reference from the provided
arguments. Content table supports unlimited numeric arguments, in
addition to Section, Detail, Quote, Quotee and Suffix arguments.
@param content - table - The content of the reference
@return wikitext - the constructed reference text
]]
function makeRefText( content )
local text = ''
return text
end
--[[[
Constructs wikitext to reuse an existing reference with the given id, in the
given group.
@param frame - object - The current parser frame
@param id - string - The id to give to the reference
@param group - string - The group to include the reference in
@return wikitext - the constructed reference reuse wikitext
]]
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
--[[[
Constructs the list of references in a given group.
@param frame - object - The current parser frame
@param group - string - The reference group to list
@param colNum - int - The number of columns to use in the list
@param colWidth - int - The width list columns should be
@param colGap - int - The size of the gap between list columns
@return wikitext - the constructed reference
]]
function makeList( frame, group, colNum, colWidth, colGap )
local args = {}
if not utils.empty( group ) then
args.group = tostring( group )
end
return frame:extensionTag( 'references', '', args )
end
--------------------------------------------------------------------------------
------------------------------- PUBLIC FUNCTIONS -------------------------------
--------------------------------------------------------------------------------
local ref = {}
--[[[
Invocation entry point for Template:Ref. Takes arguments Id, Name, Group and
Text from the template parser frame and constructs the appropriate reference.
@param frame - object - The current parser frame
@return wikitext - the constructed reference
]]
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
--[[[
Invocation entry point for Template:Ref/List. Takes argument Group from the
template parser frame and constructs the appropriate reference list.
@param frame - object - The current parser frame
@return wikitext - the constructed reference list
]]
function ref.list( frame )
local templateFrame = frame:getParent()
local group = templateFrame.args['Group']
return makeList( frame, group, colNum, colWidth, colGap )
end
--[[[
Invocation entry point for Template:Ref/Generic. Currently unimplemented.
@param frame - object - The current parser frame
@return wikitext - the constructed reference
]]
function ref.generic( frame )
local args, out = arguments.preprocess( frame, {
[ 'valid' ] = { 'id', 'subheading', 3, 4, 5, 6, 7, 'detail', 'quote',
'quotee', 'quoteelinktext', 'suffix' },
[ 'recommended' ] = { 2 },
[ 'required' ] = { 'heading' },
[ 'aliases' ] = { [ 1 ] = 'heading' }
})
return out .. args.heading
end
return ref