Deze module is nog in ontwikkeling (versie 0.0) en wordt getest.
De Module:Layout is bedoeld om snel, consistent en uitgebreid een pagina op te maken.
Er is een op de module afgestemde handleiding over deze onderwijswiki beschikbaar.
localconvert={};-- This function converts a hexadecimal code to r, g, bfunctionconvert.hex_to_rgb(hex)localr=tonumber(hex:sub(1,2),16);localg=tonumber(hex:sub(3,4),16);localb=tonumber(hex:sub(5,6),16);returnr,g,b;end-- This function converts a date into a age.functionconvert.date_to_age(call)localtimestamp=call.include("timestamp");localstartdate=call.unnamed[1];localenddate=call.unnamed[2];ifnottype(startdate)=="string"or#startdate<8thenreturn"";endlocalstartday,startmonth,startyear=string.gmatch(startdate,"(%d+)-(%d+)-(%d+)")();ifnottype(enddate)=="string"or#enddate<8thenenddate=mw.language.getContentLanguage():formatDate("d-m-Y");endlocalendday,endmonth,endyear=string.gmatch(enddate,"(%d+)-(%d+)-(%d+)")();-- Make sure day, month and year are numbersstartday=tonumber(startday);startmonth=tonumber(startmonth);startyear=tonumber(startyear);endday=tonumber(endday);endmonth=tonumber(endmonth);endyear=tonumber(endyear);-- Check if the dates are validifnottimestamp.valid(startday,startmonth,startyear)ornottimestamp.valid(endday,endmonth,endyear)thenreturn"";end-- Calculate age based on day and month comparisonlocalage=endyear-startyear;ifendmonth<startmonthor(endmonth==startmonthandendday<startday)thenage=age-1;endifage<0thenage=0;endreturntostring(age);end-- This function converts a text into a table if the text containts the template template_name.-- All parameters are stored as elements of the table.-- Unnamed parameters become indexed where the index represents the position in the template.-- Named parameters are stored associative.functionconvert.template_to_table(inputtext,template_name,call)-- :tablelocalpattern,text=call.include("pattern","text");-- Check if the text starts and ends with the definition of the template_name and if so remove it.inputtext=pattern.remove_template_definition(inputtext,template_name)ifnotinputtextthenreturn{};end-- Replace the | characters inside lists, templates, tables, links, headings and tags with a special character so it will not join the split-- Because we removed the template definition, the | in the template itself will not be changed.inputtext=pattern.replace_inner_pipes(inputtext);-- Split the template at the | character. We now for sure that inner wikitext elements do not join the split anymore.localparts=mw.text.split(inputtext,'|');-- Create a new table to store the template parameters and valueslocalt={};localj=1;-- start index for unnamed parametersfor_,partinipairs(parts)do-- Trim leading and trailing whitespace from the partpart=mw.text.trim(part);-- Check if the first characters form the name of a parameter.-- If the result is empty that means we're dealing with the first part that still belongs to the template definition just skip.ifnot(part=="")then-- Let's divide the part into a parametername and a parametervaluelocalparam_name=pattern.paramname(part);localparam_value=pattern.paramvalue(part);-- Put the | back. The param_name should not contain the | characteriftext.valid(param_value)thenparam_value=param_value:gsub('¦','|');elseparam_value="";endifparam_namethen-- We do have a parametername. So store it as the value of the key for the value of the parametert[param_name]=mw.text.trim(param_value,"\t\r\n\f ");else-- We do not have a parametername. The key is the position of the unnamed parameter.t[j]=mw.text.trim(param_value,"\t\r\n\f ");j=j+1;endendendreturnt;endreturnconvert;