Module:Layout/Production/Model/Luggage

 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.




local luggage = {};

-- This function will add all named parameters from the frame as parameters of the call object
-- now it is clear that there is nothing to declare on first sight (all the names of the parameters are valid)
function luggage.carry_on( call )
	-- The functions from other modules that are used in this function
	local text, array  = call.include( "text", "array" );

    -- All valid parameters are stored as hooks in the configuration
	for _, parameter in ipairs( call.hook.PARAMETER ) do
		call[ parameter ] = false;
		if call.named[ parameter ] and call.named[ parameter ] ~= "" then
			-- If the value of the parameter is not an enumeration, it does not need a translation for internal use.
			if call.message.HOOK[ string.upper( parameter ) ] == nil then
		        call[ parameter ] = call.named[ parameter ];
			else
				-- Look where in the enumeration the translated value matches the internal value. Search case-insensitive!
				local search = array.search( call.message.HOOK[ string.upper( parameter ) ], call.named[ parameter ], true );	
			    if search then 
				    call[ parameter ] = call.hook[ string.upper( parameter ) ][ search ];
			    end
		    end
		end		
    end	
	return call;
end

-- This function only claims the information needed for the onward journey.
function luggage.claim( call )
	return { 
		pass = call.pass, 
		message = call.message, 
		support = call.support, 
		debugging = call.debugging, 
		mistake = call.mistake, 
		help = call.help };
end

-- This function drops the frame and the CFG luggage into the call object for safe carrying through the right environment
function luggage.drop( call, frame, CFG, environment )
	call.CFG           = CFG;
	call.frame         = frame;
	call.version       = CFG.VERSION;
    call.template      = CFG.INTERFACE_TEMPLATE[ call.environment ];
    call.language      = CFG.LANGUAGE;
    call.language_path = "language/" .. call.language;
    call.message       = call.include( call.language_path );
    call.hook          = call.include( "hook" );
    call.style         = call.include( "style" );
    call.tones         = CFG.TONES;

	call.message.PARAM = {};
	for i, key in ipairs(call.hook.PARAMETER) do
	    local value = call.message.HOOK.PARAMETER[i];
	    call.message.PARAM[string.upper( key )] = value;
	end

	-- The functions from other modules that are used in this function
	local text  = call.include( "text" );

	call.invoker     = text.trim( call.frame:getParent():getTitle() );
	call.caller      = mw.title.getCurrentTitle();

    -- Split the frame arguments into named and unnamed parameters and make sure they all are strings.
	for key, value in pairs( frame.args ) do
        if type( key ) == "string" then
            call.named[ key ] = tostring( value );
        else
            call.unnamed[ key ] = tostring( value );	
        end
	end

    -- Make a translation of the array of valid objects by looking into the object's language file
    -- Store the translation into a new message object.
    call.message.HOOK.OBJECT = {};
    call.message.OBJECT = {};
    
    -- Look for every valid object as declared in the hook configuration if there is a language file with a object name in that language
    for index, objectname in ipairs( call.hook.OBJECT ) do
		local object_language_path = call.language_path .. "/" .. objectname;
		local object_language = call.include( object_language_path );
		if object_language ~= nil and object_language.NAME ~= nil then
		    call.message.HOOK.OBJECT[ index ] = object_language.NAME;
		    call.message.OBJECT[string.upper(objectname)] = object_language.NAME
		end
	end
	
	return call;
end

-- This function converts and/or extends the call parameters so it can be loaded for passing to the view.
function luggage.loading( call )
	-- The functions from other modules that are used in this function
	local inventory = call.include( "inventory" );

    -- Convert and complete the values of the valid parameters passed
    for _, parameter in ipairs( call.hook.PARAMETER ) do
        if type( inventory[ parameter] ) == "function" then call[ parameter ] = inventory[ parameter ]( call ); end
    end

    -- Add messages specific to the choosen object
    for index, objectname in ipairs( call.hook.OBJECT ) do
		local object_language_path = call.language_path .. "/" .. objectname;
		local object_language = call.include( object_language_path );
		if object_language ~= nil then
		    call.message[ string.upper( objectname ) ] = object_language;
        end
	end

    -- Extend the call variable with a content that is specific to the type of the object
    local content = call.include( "content/" .. call.object );
    if content then call = content.main( call ); end

    return call;
end

return luggage;
Informatie afkomstig van https://nl.wikibooks.org Wikibooks NL.
Wikibooks NL is onderdeel van de wikimediafoundation.