Naar inhoud springen


Uit Wikibooks
 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.

De module wordt geïnitialiseerd met de configuratie in Module:Layout/Production/Configuration.

Controleer op scriptfouten of opmaak notificaties.

-- Although locally declared this variables are used as shared between different modules
local CFG = {}

CFG.VERSION            = "0.0";
CFG.LANGUAGE           = "NL";
	production  = "Sjabloon:Opmaak", 
	stage       = "Sjabloon:Opmaak/Wachtruimte", 
	development = "Sjabloon:Opmaak/Werkplaats", 
	sandbox     = "Sjabloon:Opmaak/Zandbak"
CFG.LOCATIONS          = { "", "Configuration/", "Model/", "Interface/", "View/", "Library/" } -- Search in these paths
CFG.ENVIRONMENTS       = { "sandbox", "development", "stage", "production" }                   -- Valid environments in searchorder
CFG.TONES              = 10;                                                                   -- Number of tones in color

-- This function returns submodules based on the title(s) given in the arguments and the current environment
-- Titles may use Title/Subtitle as an argument
function CFG.INCLUDE( environment, ... )                                                                  -- : unpack of LUA submodules
    -- The variable number of arguments are the module names
    local modules   = {...};
    local found_environment = nil;
    for index, value in ipairs( CFG.ENVIRONMENTS ) do
        if value == environment then
            found_environment = index;
    local includes = {};                                                                     -- Store loading modules in the includes array

    -- Look starting from the environment up to the production environment for changed modules.
    -- If no environment is found then use the production environment
    for i = found_environment or #CFG.ENVIRONMENTS, #CFG.ENVIRONMENTS do
        environment = CFG.ENVIRONMENTS[ i ]:gsub( "^%l", string.upper ); -- The convention for the path is uppercase first
	    for index, modulename in ipairs( modules ) do                                                 -- Loop over the arguments with the module name as value
	        if ( includes[ index ] == nil ) then 
		        -- Convert the input string into one that has capitalized first characters in the path.
		        -- With the string.gmatch() function iterate over the segments of the modulename separated by slashes. 
		        -- For each segment, capitalize the first letter and sets the rest of the segment to lowercase.
		        -- It then inserts the modified segment into a table. 
		        -- Finally, the table.concat() function is used to concatenate the table into a single output string, using the slash as the separator.
				local path_segments = {};
				for segment in string.gmatch( modulename, "([^/]+)" ) do
				    -- Capitalize the first letter and add the rest of the segment as lowercase
				    local capitalized = string.upper( string.sub( segment, 1, 1 ) ) .. string.lower( string.sub( segment, 2 ) );
				    table.insert( path_segments, capitalized );
				modulename = table.concat( path_segments, "/" );

		        for _, location in ipairs( CFG.LOCATIONS ) do
		   	        local title_path =  "Module:Layout/"   .. environment .. "/" .. location .. modulename;
		   	        if title_path ).exists then
		   	    	    includes[ index ] = require( title_path );
    return unpack( includes );                                                               -- Unpack the table and return them as separate values

return CFG;
Informatie afkomstig van Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.