Module:BethNaught/RHH
Appearance
This module can be used to assist in populating the {{RunningHeader}} template often used in page headers. Normally this requires manual editing to position the page number on the left or right; this module automatically does this based on the number's parity. The center text can also be automatically filled depending on the parity of the page number.
Usage
[edit]As an assistant to filling RunningHeaders, this module is intended to be substituted. For example, the code
{{{|{{subst:}}}#invoke:BethNaught/RHH|three|pagenum={{{pagenum}}}|center=BIBLICAL BIOLOGY.}}
placed in the header field of the index page will, upon editing a page, be rendered as e.g.
{{subst:#invoke:BethNaught/RHH|three|pagenum=5|center=BIBLICAL BIOLOGY.}}
which when saved becomes
{{RunningHeader||BIBLICAL BIOLOGY.|5}}
Parameters
[edit]- The first parameter (which is actually the module function being called) is always "three". mandatory.
- center_odd, center_even: the center text for odd- and even-numbered pages. Optional, default to empty string
- center: the center text for all pages. Optional, defaults to empty string. Overrides center_odd and center_even if specified.
- pagenum: the number of the current page. If not provided, or not an integer, an empty RunningHeader is output.
Examples
[edit]{{subst:#invoke:BethNaught/RHH|three|pagenum=600}}
{{RunningHeader|600||}}
{{subst:#invoke:BethNaught/RHH|three|pagenum=5|center=CENTER}}
{{RunningHeader||CENTER|5}}
{{subst:#invoke:BethNaught/RHH|three|pagenum=101|center_odd=ODD|center_even=EVEN}}
{{RunningHeader||ODD|101}}
{{subst:#invoke:BethNaught/RHH|three|pagenum=102|center_odd=ODD|center_even=EVEN}}
{{RunningHeader|102|EVEN|}}
-- A module to automate the positioning of the page number in a RunningHeader
-- based on its parity, and for related purposes.
-- © 2018 BethNaught, CC BY-SA 3.0
local p = {}
function p.three(frame)
-- load arguments from frame
local center = frame.args['center']
local center_odd, center_even
if center == nil then
center_odd = frame.args['center_odd']
center_even = frame.args['center_even']
if center_odd == nil then center_odd = '' end
if center_even == nil then center_even = '' end
else
-- if center is provided, it overrides specific odd/even values
center_odd, center_even = center, center
end
-- pagenum loaded as a string; if not specified, we get nil, so pagenum_num
-- is nil, and below we trigger the pagenum_num == nil handling block.
local pagenum = frame.args['pagenum']
local pagenum_num = tonumber(pagenum)
-- argument loading finished
-- initialise output variables
local out_left, out_center, out_right = '', '', ''
-- populate output variables based on pagenumber
if pagenum_num == nil then
-- for now, return an empty RunningHeader in this case
elseif pagenum_num % 2 == 0 then
out_left = pagenum
out_center = center_even
elseif pagenum_num % 2 == 1 then
out_right = pagenum
out_center = center_odd
end
-- time to return our RunningHeader
return '{{RunningHeader|' .. out_left .. '|' .. out_center .. '|' .. out_right .. '}}'
end
return p