Baustelle.svg Eine Bearbeitungssperre steht an, welche von 23. Januar bis einschließlich 25. Januar dauern wird. In dieser Zeit wird das FürthWiki weiterhin lesbar, aber nicht bearbeitbar sein.

Modul:Common: Unterschied zwischen den Versionen

Aus FürthWiki

Verschiebung Kalender-Funktionen zu Modul:Kalender, - obsolete Funktionen
Keine Bearbeitungszusammenfassung
(Verschiebung Kalender-Funktionen zu Modul:Kalender, - obsolete Funktionen)
 
(37 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt)
Zeile 1: Zeile 1:
local p = {}
local p = {}


function p.AttributeTable(args)
function p.attributeTable(args)
-- Draws a simple Table that contains all arguments that are fed from the
-- Draws a simple Table that contains all arguments that are fed from the
-- template to the scribunto-model. For debugging only!
-- template to the scribunto-model. For debugging only!
Zeile 11: Zeile 11:
t = t .. '</table>'
t = t .. '</table>'
return t
return t
end
function p.IstJahrestag(frame)
-- #invoke wrapper
local args = frame.args
    local title = mw.title.getCurrentTitle().text
    local tag, monat = p.istJahrestag(title)
   
    if tag and monat then
        return frame.args[1] or "true"
    else
        return frame.args[2] or ""
    end
end
function p.istJahrestag(s)
s = s or ""
-- Prüfe auf ein-/zweistellige Zahl durch Punkt gefolgt, opt. Leerzeichen
return s:match("^(%d%d?)%.%s*(%a+)$")
end
function p.IstJahreszahl(frame)
-- #invoke wrapper
    local args = frame.args
    local title = mw.title.getCurrentTitle().text
    if p.istJahreszahl(title) then
        return args[1] or "true"
    else
        return args[2] or ""
    end
end
function p.istJahreszahl(s)
s = s or ""
-- Prüfe auf Formate wie: 2024, -44, 44 v. Chr., 800 n. Chr.
return s:match("^%-?%d+$") or s:match("^%d+%s+[vn]%.%s+Chr%.$")
end
end


Zeile 62: Zeile 25:
end
end


function p.getMonthList()
function p.isEmpty(a)
-- Returns a numbered List of all monthnames
if type(a) == "table" then
return {
for _ in pairs(a) do
[1] = "Januar",
return false
[2] = "Februar",
[3] = "März",
[4] = "April",
[5] = "Mai",
[6] = "Juni",
[7] = "Juli",
[8] = "August",
[9] = "September",
[10] = "Oktober",
[11] = "November",
[12] = "Dezember"}
end
 
function p.getMonthnr(name)
-- Returns the number of the given monthname
local months = p.getMonthList()
for nr, mn in pairs(months) do
if mn == name then
return nr
end
end
return true
else
return a == '' or a == nil
end
end
end
function p.isEmpty(a)
return a == '' or a == nil
end
end


Zeile 119: Zeile 62:
end
end


function p.get_key_for_value( t, value )
function p.get_key_for_value(t, value)
for k, v in pairs(t) do
for k, v in pairs(t) do
if v==value then return k end
if v == value then
return k
end
end
end
return nil
end
end


Zeile 134: Zeile 78:
for k, v in pairs(t2) do
for k, v in pairs(t2) do
result[k] = v
result[k] = v
end
return result
end
function p.append_tables(t1, t2)
-- append indexed/keyed table to another
-- indexes/keys gonna lost!
-- the result is table with new indexes
-- also see p.merge_tables()
local result={}
for _, v in pairs(t1) do
table.insert(result, v)
end
for _, v in pairs(t2) do
table.insert(result, v)
end
end
return result
return result
Zeile 145: Zeile 104:
end
end
return s
return s
end
function p.tableToString(tbl, indent)
-- Prints a LUA-Table as string. Very useful if you want to see whats inside
    indent = indent or 0
    local toprint = string.rep(" ", indent) .. "{\n"
    indent = indent + 2
    for k, v in pairs(tbl) do
        toprint = toprint .. string.rep(" ", indent)
        if type(k) == "number" then
            toprint = toprint .. "[" .. k .. "] = "
        elseif type(k) == "string" then
            toprint = toprint .. k .. " = "
        end
        if type(v) == "number" then
            toprint = toprint .. v .. ",\n"
        elseif type(v) == "string" then
            toprint = toprint .. "\"" .. v .. "\",\n"
        elseif type(v) == "table" then
            toprint = toprint .. tableToString(v, indent + 2) .. ",\n"
        else
            toprint = toprint .. "\"" .. tostring(v) .. "\",\n"
        end
    end
    toprint = toprint .. string.rep(" ", indent - 2) .. "}"
    return toprint
end
end


function p.shallowcopy(orig)
function p.shallowcopy(orig)
-- real-copy of a table
     local orig_type = type(orig)
     local orig_type = type(orig)
     local copy
     local copy
Zeile 187: Zeile 121:
end
end


function p.page_of_subobjekt(frame)
function p.isTrue(s)
local args = frame:getParent().args
-- testet String auf True-Werte verschiedenster Schreibweisen
    return args[1]
local result = false
--    return tostring(string.find(tostring(frame.args[1]),"#"))
if s ~= nil then
if type(s) == "boolean" then
result = s
elseif type(s) == "number" then
result = (s ~= 0)
else
s = tostring(s)
result = (s == "Ja" or s == "ja" or s == "Wahr" or s == "wahr" or s == "true")
end
end
return result
end
end


return p
return p