Module:sectionibus

E Victionario

Usus[+/-]

Usurpatur in “Module:sectio


-- Copy of the [[:fr:Module:section article]]
-- Modified and maintained by: Usor:DenisWasRight

b = require('Module:basis')

-- Charge la table une fois pour toutes pour ce module
local titles = mw.loadData('Module:sectionibus/data')

local p = {}

-- Récupère un objet pour le type de section demandé
function _get_type(word)
    if word == nil then return nil end
    
    -- Pour chercher dans les listes, on autorise éventuellement les majuscules en début de mot
    word = b.lcfirst(word)
	
    -- Alias?
    if p.is_alias(word) then
        word = titles['alias'][word]
    end
    
    -- Titre défini?
    if titles['text'][word] ~= nil then
        return titles['text'][word]
    else
    	return nil
    end
end

-- S'agit-il d'un alias?
function p.is_alias(word)
    if word == nil then return nil end
    
    word = b.lcfirst(word)
    
    if titles['alias'][word] then
        return true
    else
        return false
    end
end

-- S'agit-il d'un titre de section reconnu (ou d'un alias) ?
function p.is_title(word)
    if word == nil then return nil end
    
    -- Récupération de l'objet correspondant à ce type de mot, s'il existe
    local word_type = _get_type(word)
    
    -- L'objet existe, donc c'est bien une section autorisée
    if word_type ~= nil then
        return true
    else
        return false
    end
end

-- Fonction de récupération du nom standard à partir de son code et de ses propriétés
function p.get_name_section(word)
    if word == nil then return nil end
    
    -- Récupération de l'objet correspondant à ce type de mot, s'il existe
    local word_type = _get_type(word)
    
    -- L'objet existe, on peut renvoyer son nom
    if (word_type ~= nil) then
        return word_type['name']
    else
        return nil
    end
end

-- Fonction de récupération de la classe d'un titre
function p.get_class(word)
    if word == nil then return nil end
    
    -- Récupération de l'objet correspondant à ce type de mot, s'il existe
    local word_type = _get_type(word)
    
    -- L'objet existe, on peut renvoyer sa classe
    if word_type ~= nil then
        return word_type['class']
    else
        return nil
    end
end

return p