Jump to content
Wikipedia The Free Encyclopedia

Module:MasterGunner

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
This module is rated as beta. It is considered ready for widespread use, but as it is still relatively new, it should be applied with some caution to ensure results are as expected.

Usage

[edit ]

{{#invoke:MasterGunner|GunnerBox}}

Please see {{Template:MasterGunner}} for example usage

The above documentation is transcluded from Module:MasterGunner/doc. (edit | history)
Editors can experiment in this module's sandbox (create | mirror) and testcases (create) pages.
Subpages of this module.

 require('strict')
 localp={}
 localdata=mw.loadData('Module:MasterGunner/data')
 localgetArgs=require('Module:Arguments').getArgs
 -- South African Master Gunner Data
 -- Data Fields
 -- Code: This is just a duplicate of the lookup code, but expressed as a number instead of a string
 -- Rank: Person's rank. Not wikilinked
 --- FirstName: Initials or first name(s)
 -- Surname: Person's Surname
 -- Year: Year appointed Master Gunner
 -- WikiPage: If the person has a Wiki article, name of the article here
 -- PostNoms: list of Post Nominal Titles. Stored in Lua table format ie Curly braces with values seperated by commas
 -- Post: The name of the post that they held when awarded. Commas will be turned into line breaks
 -- Note: Any additional info about this Gunner.
 -- RecipCat: Category for recipients. "List of Master Gunners (South Africa)"

 functionp.Gunner(frame)
 localoutput=''
 localtemplateArgs=getArgs(frame)
 localgunnercode=templateArgs["code"]ornil
 -- local pagename=templateArgs["pagename"] or nil
 ifnotgunnercodethen
 output='<span style="color:#d33">Error: No code specified</span>'
 returnoutput
 end
 ifdata[gunnercode]then
 output=output..gunnercode..": "
 output=output..data[gunnercode].Code.." Master Gunner".."<br />"
 output=output..data[gunnercode].FirstName.." "..data[gunnercode].Surname.." Year: "..data[gunnercode].Year.."<br />"
 returnoutput
 else
 output='<span style="color:#d33">Error: code '..gunnercode..' not found</span>'
 end
 returnoutput
 end

 functionp.GunnerBox(frame)
 localoutput=''
 localtemplateArgs=getArgs(frame)
 localgunnercode=templateArgs["code"]ornil
 localimagesize=templateArgs["imagesize"]or'150px'
 ifnotgunnercodethen
 output='<span style="color:#d33">Error: No "code" specified. Use the Gunner number preceded by an A for example, code=A100</span>[[Category:Master Gunner Error]]'
 returnoutput
 end

 ifdata[gunnercode]then
 -- Send Info
 -- Generate wiki table code for the Master Gunner

 localfloat=templateArgs.floator'none'
 iffloat=="left"then
 float="floatleft"
 elseiffloat=="right"then
 float="floatright"
 elseiffloat=="none"then
 float=''
 end

 localtableCode='{| class="wikitable '..float..'" style="text-align:center" \n'
 --		tableCode = tableCode .. "|+ Master Gunner \n" -- Caption
 tableCode=tableCode.."|-\n"
 tableCode=tableCode..'!colspan=2 style="background:red; color:white;"| Master Gunner: '..data[gunnercode].Code..'\n'
 tableCode=tableCode.."|-\n"
 tableCode=tableCode.."|colspan=2|[[file:SANDF Arty Master Gunner badge embossed.png|border|"..imagesize.."|link=List of badges of the South African Army#Proficiency: Master Gunner|Master Gunner]]\n"
 tableCode=tableCode.."|-\n"
 tableCode=tableCode.."|colspan=2|"..p.GetGunner("A"..data[gunnercode].Code)
 ifstring.len(data[gunnercode].Post)>1then
 tableCode=tableCode..mw.getCurrentFrame():expandTemplate{title='Efn',args={"Post occupied when award was made: "..data[gunnercode].Post}}
 end
 ifstring.len(data[gunnercode].Note)>1then
 tableCode=tableCode..mw.getCurrentFrame():expandTemplate{title='Efn',args={data[gunnercode].Note}}
 end
 tableCode=tableCode.."\n"
 tableCode=tableCode.."|-\n "
 tableCode=tableCode.."|colspan=2|[[Master Gunners of the South African Army|Year]]: '''"..data[gunnercode].Year.."'''\n"
 tableCode=tableCode.."|-\n"
 localprevgunner="A"..data[gunnercode].Code-1..""
 tableCode=tableCode.."| ←"..data[gunnercode].Code-1..": "..p.GetGunner(prevgunner).."\n"
 localnextgunner="A"..data[gunnercode].Code+1..""
 tableCode=tableCode.."| "..p.GetGunner(nextgunner).." :"..data[gunnercode].Code+1.."→\n"
 tableCode=tableCode.."|}"
 returntableCode
 end
 returnoutput
 end
 functionp.GetGunner(gunnercode)
 localoutput=''
 ifnotdata[gunnercode]then
 output="Unknown"
 else
 ifstring.len(data[gunnercode].WikiPage)<1then
 output=data[gunnercode].Rank.."<br />"..data[gunnercode].FirstName.." "..data[gunnercode].Surname
 else
 output=data[gunnercode].Rank.."<br />".."[["..data[gunnercode].WikiPage.."|"..data[gunnercode].FirstName.." "..data[gunnercode].Surname.."]]"
 end
 end
 returnoutput-- Should never get here, but belts-and -braces... just to be sure
 end

 functionp.GunnerTable(frame)
 -- Data Fields
 -- Code: This is just a duplicate of the lookup code, but expressed as a number instead of a string
 -- Rank: Person's rank. Not wikilinked
 --- FirstName: Initials or first name(s)
 -- Surname: Person's Surname
 -- Year: Year appointed Master Gunner
 -- WikiPage: If the person has a Wiki article, name of the article here
 -- PostNoms: list of Post Nominal Titles. Stored in Lua table format ie Curly braces with values seperated by commas
 -- Post: The name of the post that they held when awarded. Commas will be turned into line breaks
 -- Note: Any additional info about this Gunner.
 -- RecipCat: Category for recipients. "List of Master Gunners (South Africa)"
 localoutput=''
 localtemplateArgs=getArgs(frame)
 locallocalfloat=templateArgs["float"]or''
 ifnotlocalfloatthen
 localfloat="left"-- NOTE TODO: Make the table float according to the value of locafloat ;-)
 end
 localtableCode='{| class="wikitable sortable" \n'
 tableCode=tableCode.."|+ List of Master Gunners \n"-- Caption
 tableCode=tableCode.."|-\n"
 tableCode=tableCode.."! Code !!Number !! Rank !! Surname !! First Names !! Post !! Year !! Note \n"
 -- Iterate through the data in the table "GunnerData"
 forcode,recordinpairs(data)do
 -- Generate wiki table code for the Master Gunner
 -- TODO: If record.Surname == "Unknown" make the row distinctive somehow.
 tableCode=tableCode.."|-\n"
 tableCode=tableCode.."|"..code.."\n"
 tableCode=tableCode.."| "..record.Code.."\n"
 tableCode=tableCode.."| "..record.Rank.."\n"
 ifstring.len(record.WikiPage)<1then
 tableCode=tableCode.."| "..record.Surname
 else
 tableCode=tableCode.."| ".."[["..record.WikiPage.."|"..record.Surname.."]]"
 end
 --	if string.len(record.Post)>1 then
 --		tableCode = tableCode .. mw.getCurrentFrame():expandTemplate{ title = 'Efn', args = {"Post occupied when award was made: " .. record.Post} }
 --	end
 tableCode=tableCode.."\n"
 tableCode=tableCode.."| "..record.FirstName.."\n"
 tableCode=tableCode.."| "..string.gsub(record.Post,","," - <br />").."\n"
 tableCode=tableCode.."| "..record.Year.."\n"
 tableCode=tableCode.."| <small>"..record.Note.."</small>\n"

 end
 tableCode=tableCode.."|}"-- End the table
 returntableCode
 end

 returnp
 -- Initial Code by John Dovey (13 April 2023) [[User:BoonDock]]

AltStyle によって変換されたページ (->オリジナル) /