پرش به محتوا

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

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


خط ۲۱: خط ۲۱:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- گرفتن مقدار با alias ها
-- resolve alias values
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.getValue(argTable, key)
function Citation.getValue(argTable, key)
خط ۳۹: خط ۳۹:


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


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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- رندر اصلی
-- Style Builder (citation sentence)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.render(frame, ctype)
function Citation.buildText(data, ctype, cfg, F, U)
 
    local rawArgs = Citation.getArgs(frame)
    local data    = Citation.normalize(rawArgs)
    local layout  = cfg.layouts[ctype] or cfg.layouts.web


     local parts = {}
     local parts = {}


     for _, field in ipairs(layout) do
     ----------------------------------------------------------------------
    -- author
    ----------------------------------------------------------------------
    if not U.isEmpty(data.author) then
        table.insert(parts, data.author .. ".")
    end


        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
        -- identifiers
    -- title
        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
         if field == "identifiers" then
    if not U.isEmpty(data.title) then
         table.insert(parts, "''" .. data.title .. "''.")
    end


            local ids = Citation.renderIdentifiers(data)
    ----------------------------------------------------------------------
            if not U.isEmpty(ids) then
    -- website / source
                table.insert(parts, ids)
    ----------------------------------------------------------------------
            end
    if not U.isEmpty(data.website) then
        table.insert(parts, "در: " .. data.website .. ".")
    end


        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
        -- URL
    -- publisher
        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
         elseif field == "url" then
    if not U.isEmpty(data.publisher) then
         table.insert(parts, data.publisher .. ".")
    end


            local url = F.formatUrl(data.url)
    ----------------------------------------------------------------------
            if not U.isEmpty(url) then
    -- date
                table.insert(parts, url)
    ----------------------------------------------------------------------
            end
    if not U.isEmpty(data.date) then
        table.insert(parts, data.date .. ".")
    end


        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
        -- title
    -- URL
        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
         elseif field == "title" then
    if not U.isEmpty(data.url) then
         table.insert(parts, F.formatUrl(data.url))
    end


            local title = F.formatTitle(data.title)
    ----------------------------------------------------------------------
            if not U.isEmpty(title) then
    -- identifiers
                table.insert(parts, title)
    ----------------------------------------------------------------------
            end
    local ids = Citation.renderIdentifiers(data)
    if not U.isEmpty(ids) then
        table.insert(parts, ids)
    end


        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
        -- archive
    -- archive
        ----------------------------------------------------------------------
    ----------------------------------------------------------------------
         elseif field == "archive" then
    if not U.isEmpty(data.archiveurl) then
         table.insert(parts,
            F.formatArchive(data.archiveurl, data.archivedate)
        )
    end


            local arch = F.formatArchive(data.archiveurl, data.archivedate)
    return table.concat(parts, " ")
            if not U.isEmpty(arch) then
                table.insert(parts, arch)
            end


        ----------------------------------------------------------------------
end
        -- سایر فیلدها
        ----------------------------------------------------------------------
        else


            local value = data[field]
--------------------------------------------------------------------------------
-- render main
--------------------------------------------------------------------------------
function Citation.render(frame, ctype)


            if not U.isEmpty(value) then
    local rawArgs = Citation.getArgs(frame)
                table.insert(parts, value)
    local data    = Citation.normalize(rawArgs)
            end
 
        end
    end


     local result = table.concat(parts, cfg.separator)
     local result = Citation.buildText(data, ctype, cfg, F, U)


     return U.cleanEnd(result)
     return U.cleanEnd(result)

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

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

--------------------------------------------------------------------------------
-- Module:Citation
-- Wiki Alborz Simple Citation System (Final Integrated 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

--------------------------------------------------------------------------------
-- resolve alias values
--------------------------------------------------------------------------------
function Citation.getValue(argTable, key)
    local aliases = cfg.aliases[key]
    if not aliases then
        return nil
    end

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

    return nil
end

--------------------------------------------------------------------------------
-- normalize input
--------------------------------------------------------------------------------
function Citation.normalize(args)
    local out = {}

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

    return out
end

--------------------------------------------------------------------------------
-- identifiers (DOI / ISBN / etc.)
--------------------------------------------------------------------------------
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

--------------------------------------------------------------------------------
-- Style Builder (citation sentence)
--------------------------------------------------------------------------------
function Citation.buildText(data, ctype, cfg, F, U)

    local parts = {}

    ----------------------------------------------------------------------
    -- author
    ----------------------------------------------------------------------
    if not U.isEmpty(data.author) then
        table.insert(parts, data.author .. ".")
    end

    ----------------------------------------------------------------------
    -- title
    ----------------------------------------------------------------------
    if not U.isEmpty(data.title) then
        table.insert(parts, "''" .. data.title .. "''.")
    end

    ----------------------------------------------------------------------
    -- website / source
    ----------------------------------------------------------------------
    if not U.isEmpty(data.website) then
        table.insert(parts, "در: " .. data.website .. ".")
    end

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

    ----------------------------------------------------------------------
    -- date
    ----------------------------------------------------------------------
    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

    ----------------------------------------------------------------------
    -- identifiers
    ----------------------------------------------------------------------
    local ids = Citation.renderIdentifiers(data)
    if not U.isEmpty(ids) then
        table.insert(parts, ids)
    end

    ----------------------------------------------------------------------
    -- archive
    ----------------------------------------------------------------------
    if not U.isEmpty(data.archiveurl) then
        table.insert(parts,
            F.formatArchive(data.archiveurl, data.archivedate)
        )
    end

    return table.concat(parts, " ")

end

--------------------------------------------------------------------------------
-- render main
--------------------------------------------------------------------------------
function Citation.render(frame, ctype)

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

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

    return U.cleanEnd(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