|
|
| (12 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 160: |
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
| |
| -- to do: still neccessary? => mw.logObject()
| |
| 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 |
|
| |
|
| Zeile 202: |
Zeile 119: |
| end | | end |
| return copy | | return copy |
| end
| |
|
| |
| function p.templateTranscludeWithArgs(frame)
| |
| local args = p.shallowcopy(frame:getParent().args) -- frame:getParent().args als Basis nehmen
| |
| local template = frame.args[1] -- enthält Vorlagen-Seitenname
| |
| for orig_key, orig_value in pairs(frame.args) do -- über alle args iterieren, um parentargs mit args anzureichern
| |
| if type(orig_key) == 'number' then -- bei numerierten Parametern...
| |
| if orig_key > 1 then -- ... eine Index-Verschiebung durchführen, weil ...
| |
| args[orig_key-1] = orig_value -- ... args[1] enthält Vorlagen-Seitenname, der
| |
| end -- nicht übernommen wird
| |
| else
| |
| args[orig_key] = orig_value -- bei nicht-Nummern-Index 1:1 kopieren
| |
| end
| |
| end
| |
| return frame:expandTemplate{title=template, args=args}
| |
| end | | end |
|
| |
|
| Zeile 222: |
Zeile 124: |
| -- testet String auf True-Werte verschiedenster Schreibweisen | | -- testet String auf True-Werte verschiedenster Schreibweisen |
| local result = false | | local result = false |
| if not p.isEmpty(s) then | | if s ~= nil then |
| if type(s) == "number" then | | if type(s) == "boolean" then |
| | result = s |
| | elseif type(s) == "number" then |
| result = (s ~= 0) | | result = (s ~= 0) |
| else | | else |
| s = tostring(s) | | s = tostring(s) |
| result = ( s == "Ja" or s == "ja" or s == "Wahr" or s == "wahr" or s == "true") | | result = (s == "Ja" or s == "ja" or s == "Wahr" or s == "wahr" or s == "true") |
| end | | end |
| end | | end |