پرش به محتوا

پودمان:Citation: تفاوت میان نسخه‌ها

از ویکی البرز
جزبدون خلاصۀ ویرایش
جزبدون خلاصۀ ویرایش
خط ۱: خط ۱:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Module:Citation
-- Module:Citation
-- Wiki Alborz Simple Citation System (Final Integrated Version)
-- Wiki Alborz Lightweight Citation System (Stable Final Version)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


خط ۱۲: خط ۱۲:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- گرفتن آرگومان‌ها
-- گرفتن آرگومان‌ها از الگو
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.getArgs(frame)
function Citation.getArgs(frame)
خط ۲۱: خط ۲۱:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- resolve alias values
-- پیدا کردن مقدار با alias ها
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.getValue(argTable, key)
function Citation.getValue(argTable, key)
خط ۳۰: خط ۳۰:


     for _, name in ipairs(aliases) do
     for _, name in ipairs(aliases) do
         if argTable[name] and argTable[name] ~= "" then
         local v = argTable[name]
             return argTable[name]
        if v and v ~= "" then
             return v
         end
         end
     end
     end
خط ۳۹: خط ۴۰:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- normalize input
-- نرمال‌سازی ورودی‌ها (یکسان‌سازی پارامترها)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.normalize(args)
function Citation.normalize(args)
خط ۵۲: خط ۵۳:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- identifiers (DOI / ISBN / etc.)
-- ساخت شناسه‌ها (DOI / ISBN / ...)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.renderIdentifiers(data)
function Citation.renderIdentifiers(data)
خط ۶۷: خط ۶۸:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Style Builder (citation sentence)
-- ساخت متن نهایی یادکرد (Citation Builder)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.buildText(data, ctype, cfg, F, U)
function Citation.buildText(data, ctype)


     local parts = {}
     local parts = {}


     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     -- author
     -- نویسنده
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     if not U.isEmpty(data.author) then
     if not U.isEmpty(data.author) then
خط ۸۱: خط ۸۲:


     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     -- title
     -- عنوان (italic)
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     if not U.isEmpty(data.title) then
     if not U.isEmpty(data.title) then
خط ۸۸: خط ۸۹:


     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     -- website / source
     -- وبگاه / منبع
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     if not U.isEmpty(data.website) then
     if not U.isEmpty(data.website) then
خط ۹۵: خط ۹۶:


     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     -- publisher
     -- ناشر
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     if not U.isEmpty(data.publisher) then
     if not U.isEmpty(data.publisher) then
خط ۱۰۲: خط ۱۰۳:


     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     -- date
     -- تاریخ
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     if not U.isEmpty(data.date) then
     if not U.isEmpty(data.date) then
خط ۱۱۶: خط ۱۱۷:


     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     -- identifiers
     -- شناسه‌ها
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     local ids = Citation.renderIdentifiers(data)
     local ids = Citation.renderIdentifiers(data)
خط ۱۲۴: خط ۱۲۵:


     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     -- archive
     -- آرشیو
     ----------------------------------------------------------------------
     ----------------------------------------------------------------------
     if not U.isEmpty(data.archiveurl) then
     if not U.isEmpty(data.archiveurl) then
خط ۱۳۳: خط ۱۳۴:


     return table.concat(parts, " ")
     return table.concat(parts, " ")
end
--------------------------------------------------------------------------------
-- پاکسازی نهایی خروجی (polish layer ساده و امن)
--------------------------------------------------------------------------------
function Citation.polish(text)
    if not text then
        return ""
    end
    text = mw.text.trim(text)
    text = text:gsub("%s+", " ")
    text = text:gsub("%s+%.", ".")
    text = text:gsub("%.+", ".")
    text = text:gsub("%s+%.?$", "")


    return text
end
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- render main
-- رندر اصلی
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.render(frame, ctype)
function Citation.render(frame, ctype)
خط ۱۴۴: خط ۱۶۱:
     local data    = Citation.normalize(rawArgs)
     local data    = Citation.normalize(rawArgs)


     local result = Citation.buildText(data, ctype, cfg, F, U)
     local result = Citation.buildText(data, ctype)


     return U.cleanEnd(result)
     return Citation.polish(result)
end
end


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- entry points
-- entry points (الگوها)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.web(frame)
function Citation.web(frame)

نسخهٔ ‏۳۰ ژوئن ۲۰۲۶، ساعت ۲۱:۱۴

توضیحات این پودمان می‌تواند در پودمان:Citation/توضیحات قرار گیرد.

--------------------------------------------------------------------------------
-- Module:Citation
-- Wiki Alborz Lightweight Citation System (Stable Final Version)
--------------------------------------------------------------------------------

local args = require("Module:Arguments")
local cfg  = require("Module:Citation/Configuration")
local U    = require("Module:Citation/Utilities")
local F    = require("Module:Citation/Formatter")

local Citation = {}

--------------------------------------------------------------------------------
-- گرفتن آرگومان‌ها از الگو
--------------------------------------------------------------------------------
function Citation.getArgs(frame)
    return args.getArgs(frame, {
        parentOnly = true
    })
end

--------------------------------------------------------------------------------
-- پیدا کردن مقدار با alias ها
--------------------------------------------------------------------------------
function Citation.getValue(argTable, key)
    local aliases = cfg.aliases[key]
    if not aliases then
        return nil
    end

    for _, name in ipairs(aliases) do
        local v = argTable[name]
        if v and v ~= "" then
            return v
        end
    end

    return nil
end

--------------------------------------------------------------------------------
-- نرمال‌سازی ورودی‌ها (یکسان‌سازی پارامترها)
--------------------------------------------------------------------------------
function Citation.normalize(args)
    local out = {}

    for key, _ in pairs(cfg.aliases) do
        out[key] = Citation.getValue(args, key)
    end

    return out
end

--------------------------------------------------------------------------------
-- ساخت شناسه‌ها (DOI / ISBN / ...)
--------------------------------------------------------------------------------
function Citation.renderIdentifiers(data)
    local parts = {}

    for key, label in pairs(cfg.identifiers) do
        if data[key] and data[key] ~= "" then
            table.insert(parts, label .. " " .. data[key])
        end
    end

    return table.concat(parts, cfg.separator)
end

--------------------------------------------------------------------------------
-- ساخت متن نهایی یادکرد (Citation Builder)
--------------------------------------------------------------------------------
function Citation.buildText(data, ctype)

    local parts = {}

    ----------------------------------------------------------------------
    -- نویسنده
    ----------------------------------------------------------------------
    if not U.isEmpty(data.author) then
        table.insert(parts, data.author .. ".")
    end

    ----------------------------------------------------------------------
    -- عنوان (italic)
    ----------------------------------------------------------------------
    if not U.isEmpty(data.title) then
        table.insert(parts, "''" .. data.title .. "''.")
    end

    ----------------------------------------------------------------------
    -- وبگاه / منبع
    ----------------------------------------------------------------------
    if not U.isEmpty(data.website) then
        table.insert(parts, "در: " .. data.website .. ".")
    end

    ----------------------------------------------------------------------
    -- ناشر
    ----------------------------------------------------------------------
    if not U.isEmpty(data.publisher) then
        table.insert(parts, data.publisher .. ".")
    end

    ----------------------------------------------------------------------
    -- تاریخ
    ----------------------------------------------------------------------
    if not U.isEmpty(data.date) then
        table.insert(parts, data.date .. ".")
    end

    ----------------------------------------------------------------------
    -- URL
    ----------------------------------------------------------------------
    if not U.isEmpty(data.url) then
        table.insert(parts, F.formatUrl(data.url))
    end

    ----------------------------------------------------------------------
    -- شناسه‌ها
    ----------------------------------------------------------------------
    local ids = Citation.renderIdentifiers(data)
    if not U.isEmpty(ids) then
        table.insert(parts, ids)
    end

    ----------------------------------------------------------------------
    -- آرشیو
    ----------------------------------------------------------------------
    if not U.isEmpty(data.archiveurl) then
        table.insert(parts,
            F.formatArchive(data.archiveurl, data.archivedate)
        )
    end

    return table.concat(parts, " ")
end

--------------------------------------------------------------------------------
-- پاکسازی نهایی خروجی (polish layer ساده و امن)
--------------------------------------------------------------------------------
function Citation.polish(text)
    if not text then
        return ""
    end

    text = mw.text.trim(text)
    text = text:gsub("%s+", " ")
    text = text:gsub("%s+%.", ".")
    text = text:gsub("%.+", ".")
    text = text:gsub("%s+%.?$", "")

    return text
end

--------------------------------------------------------------------------------
-- رندر اصلی
--------------------------------------------------------------------------------
function Citation.render(frame, ctype)

    local rawArgs = Citation.getArgs(frame)
    local data    = Citation.normalize(rawArgs)

    local result  = Citation.buildText(data, ctype)

    return Citation.polish(result)
end

--------------------------------------------------------------------------------
-- entry points (الگوها)
--------------------------------------------------------------------------------
function Citation.web(frame)
    return Citation.render(frame, "web")
end

function Citation.book(frame)
    return Citation.render(frame, "book")
end

function Citation.news(frame)
    return Citation.render(frame, "news")
end

function Citation.journal(frame)
    return Citation.render(frame, "journal")
end

--------------------------------------------------------------------------------
return Citation