Модул:Раздел статия

От Уикиречник

Документация за този модул може да бъде създадена на Модул:Раздел статия/doc

--
-- Copied and adapted from [[fr:Module:section article]] (revision=15450659) 
-- 
-- Author : [[fr:User:Darkdadaah]]
-- Adaptation : [[bg:User:D.s.m(h)]]
--
-- 2017-13-02 -- last modified by D.s.m(h)
--

b = require('Модул:Основа')

-- Charge la table une fois pour toutes pour ce module
local titles = mw.loadData('Модул:Раздел статия/Данни')

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