پرش به محتوا

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

از ویکی البرز
صفحه‌ای تازه حاوی «-------------------------------------------------------------------------------- -- Module:Citation -- هسته اصلی سامانه یادکرد ساده -------------------------------------------------------------------------------- local args = require("Module:Arguments") local cfg = require("Module:Citation/Configuration") local U = require("Module:Citation/Utilities") local Citation = {} ----------------------------------...» ایجاد کرد
 
جزبدون خلاصۀ ویرایش
خط ۱: خط ۱:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Module:Citation
-- Module:Citation
-- هسته اصلی سامانه یادکرد ساده
-- Simple Citation System (Wiki Alborz)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


خط ۷: خط ۷:
local cfg  = require("Module:Citation/Configuration")
local cfg  = require("Module:Citation/Configuration")
local U    = require("Module:Citation/Utilities")
local U    = require("Module:Citation/Utilities")
local F    = require("Module:Citation/Formatter")


local Citation = {}
local Citation = {}


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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- پیدا کردن مقدار با استفاده از alias ها
-- گرفتن مقدار با alias ها
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.getValue(argTable, key)
function Citation.getValue(argTable, key)
خط ۳۸: خط ۳۹:


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


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- انتخاب layout بر اساس نوع
-- ساخت شناسه‌ها (DOI / ISBN / ...)
--------------------------------------------------------------------------------
function Citation.getLayout(citationType)
    return cfg.layouts[citationType] or cfg.layouts.web
end
 
--------------------------------------------------------------------------------
-- ساخت بخش identifiers (DOI, ISBN, etc.)
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.renderIdentifiers(data)
function Citation.renderIdentifiers(data)
خط ۷۳: خط ۶۷:


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- رندر ساده یک citation item
-- رندر اصلی
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
function Citation.renderItem(label, value)
function Citation.render(frame, ctype)
    if U.isEmpty(value) then
        return ""
    end
    return label .. value
end


--------------------------------------------------------------------------------
-- رندر نهایی citation
--------------------------------------------------------------------------------
function Citation.render(frame, ctype)
     local rawArgs = Citation.getArgs(frame)
     local rawArgs = Citation.getArgs(frame)
     local data    = Citation.normalize(rawArgs)
     local data    = Citation.normalize(rawArgs)
 
     local layout  = cfg.layouts[ctype] or cfg.layouts.web
     local layout  = Citation.getLayout(ctype)


     local parts = {}
     local parts = {}
خط ۹۵: خط ۷۹:
     for _, field in ipairs(layout) do
     for _, field in ipairs(layout) do


        ----------------------------------------------------------------------
        -- identifiers
        ----------------------------------------------------------------------
         if field == "identifiers" then
         if field == "identifiers" then
             local ids = Citation.renderIdentifiers(data)
             local ids = Citation.renderIdentifiers(data)
             if not U.isEmpty(ids) then
             if not U.isEmpty(ids) then
خط ۱۰۱: خط ۸۹:
             end
             end


         elseif data[field] then
        ----------------------------------------------------------------------
             table.insert(parts, data[field])
        -- URL
        ----------------------------------------------------------------------
        elseif field == "url" then
 
            local url = F.formatUrl(data.url)
            if not U.isEmpty(url) then
                table.insert(parts, url)
            end
 
        ----------------------------------------------------------------------
        -- title
        ----------------------------------------------------------------------
         elseif field == "title" then
 
            local title = F.formatTitle(data.title)
            if not U.isEmpty(title) then
                table.insert(parts, title)
            end
 
        ----------------------------------------------------------------------
        -- archive
        ----------------------------------------------------------------------
        elseif field == "archive" then
 
            local arch = F.formatArchive(data.archiveurl, data.archivedate)
             if not U.isEmpty(arch) then
                table.insert(parts, arch)
            end
 
        ----------------------------------------------------------------------
        -- سایر فیلدها
        ----------------------------------------------------------------------
        else
 
            local value = data[field]
 
            if not U.isEmpty(value) then
                table.insert(parts, value)
            end
 
         end
         end
     end
     end

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

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

--------------------------------------------------------------------------------
-- Module:Citation
-- Simple Citation System (Wiki Alborz)
--------------------------------------------------------------------------------

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
        if argTable[name] and argTable[name] ~= "" then
            return argTable[name]
        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

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

    local rawArgs = Citation.getArgs(frame)
    local data    = Citation.normalize(rawArgs)
    local layout  = cfg.layouts[ctype] or cfg.layouts.web

    local parts = {}

    for _, field in ipairs(layout) do

        ----------------------------------------------------------------------
        -- identifiers
        ----------------------------------------------------------------------
        if field == "identifiers" then

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

        ----------------------------------------------------------------------
        -- URL
        ----------------------------------------------------------------------
        elseif field == "url" then

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

        ----------------------------------------------------------------------
        -- title
        ----------------------------------------------------------------------
        elseif field == "title" then

            local title = F.formatTitle(data.title)
            if not U.isEmpty(title) then
                table.insert(parts, title)
            end

        ----------------------------------------------------------------------
        -- archive
        ----------------------------------------------------------------------
        elseif field == "archive" then

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

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

            local value = data[field]

            if not U.isEmpty(value) then
                table.insert(parts, value)
            end

        end
    end

    local result = table.concat(parts, cfg.separator)

    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