Modul:Common
Aus FürthWiki
Das Commons-Modul ist ein reines Import-Modul, welches immer wieder kehrende Funktionen beinhaltet, die über das Ganze Projekt hinweg immer wieder gebraucht werden.
local p = {}
function p.AttributeTable(args)
-- Draws a simple Table that contains all arguments that are fed from the
-- template to the scribunto-model. For debugging only!
t='<table class="wikitable">'
for i, v in pairs(args) do
t = t .. '<tr><td>[[Attribut:' .. i .. '|' .. i .. ']]</td>' ..
'<td>' .. v .. '</td></tr>'
end
t = t .. '</table>'
return t
end
function p.getPageName(frame)
-- This is for unlinking semantic attributes with datatype site.
p = frame.args[1] or ""
-- Throw away all text after |
t = mw.ustring.match(p, "([^|]+)")
-- Throw away everything before [[:
t = mw.ustring.match(t, "%[%[:(.+)")
-- Next line was to check, what that span of subobjects does
--t = '<span class="smw-subobject-entity">'..t..'</span>'
return t
end
function getMonthList()
return {
[1] = "Januar",
[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 isEmpty(a)
return a == '' or a == nil
end
function contains(list, str)
for i, v in ipairs(list) do
if v == str then
return true
end
end
return false
end
function isInteger(str)
return not (str == "" or str:find("%D"))
end
function get_key_for_value( t, value )
for k,v in pairs(t) do
if v==value then return k end
end
return nil
end
function rtrim(s)
return s:gsub("%s+$", "")
end
function ltrim(s)
return s:match("^%s*(.-)$")
end
function split(s, d)
if d==nil then d="%s" end
arr={}
n=0
for i in string.gmatch(s, "[^"..d.."]+") do
arr[n]=i
n=n+1
end
return arr
end
function p.spaces(frame)
n = tonumber(frame.args[1])
s = ""
for i=0, n do
s = s .. ' '
end
return s
end
return p