Module:Dagatal
Útlit
Hægt er að búa til leiðbeiningar fyrir þessa skriftu á Module:Dagatal/doc
-- Dagatal, skrifað til að koma í staðinn fyrir snið:dagatal. Sama virkni, bara annar kóði.
local p = {}
time = require("Module:Tími")
function p.main(frame)
local pframe = frame:getParent()
local args = pframe.args
cyear = os.date("%G")
if args[1] ~= nil then
month = args[1]
else
month = time._main("F", "1" .. "-" .. math.random(1,12) .. "-" .. cyear)
end
local start = '<table align="right" class="floatright dagatal-dagur">'
local endir = '</table>'
local haus = mw.html.create("tr")
haus
:addClass("dagatal-haus")
:tag("td")
:attr("colspan", "7")
:attr("align", "center")
:wikitext("[[" .. monthlink(month, "prev") .. "]] – '''[[" .. monthlink(month) .. "]]''' – [[" .. monthlink(month, "next") .. "]]" )
:done()
:done()
local haus2 = mw.html.create("tr")
haus2
:addClass("dagatal-haus")
:tag("td")
:wikitext("[[Sunnudagur|Su]]")
:done()
:tag("td")
:wikitext("[[Mánudagur|Má]]")
:done()
:tag("td")
:wikitext("[[Þriðjudagur|Þr]]")
:done()
:tag("td")
:wikitext("[[Miðvikudagur|Mi]]")
:done()
:tag("td")
:wikitext("[[Fimmtudagur|Fi]]")
:done()
:tag("td")
:wikitext("[[Föstudagur|Fö]]")
:done()
:tag("td")
:wikitext("[[Laugardagur|La]]")
:allDone()
local tr = mw.html.create("tr")
tr
:css("text-align", "center")
:done()
local footer = mw.html.create("tr")
footer
:addClass("dagatal-haus")
:tag("td")
:attr("colspan", "7")
:css("align", "center")
:tag("small")
:wikitext("[[" .. cyear .. "]]")
:done()
:tag("br")
:done()
:wikitext("[[Allir dagar ársins|Allir dagar]]")
:allDone()
local numdays = time._main("t", month .. cyear)
local vikudagur = tonumber(time._main("w", month .. cyear))
local styles = mw.getCurrentFrame():extensionTag{
name = 'templatestyles', args = { src = "Module:Dagatal/styles.css" }
}
return styles .. start .. tostring(haus) .. tostring(haus2) .. dagar(month, numdays, vikudagur) .. tostring(tr) .. tostring(footer) .. endir
end
function monthlink(arg1, fetch)
local cyear = os.date("%G")
local lang = mw.language.getContentLanguage()
arg1 = lang:ucfirst(arg1)
if arg1 ~= nil and fetch ~= nil then
if fetch == "prev" then
arg1 = time._main("F", arg1 .. " " .. cyear .."-1 months") .. "|" .. lang:ucfirst(time._main("M", arg1 .. " " .. cyear .. "-1 months"))
elseif fetch == "next" then
arg1 = time._main("F", arg1 .. " " .. cyear .."+1 months") .. "|" .. lang:ucfirst(time._main("M", arg1 .. " " .. cyear .. "+1 months"))
end
end
if arg1 ~= nil and arg1 == "mars|Mar" or arg1 == "Mars" then
link = "mars (mánuður)|Mar"
else
link = arg1
end
return link
end
function dagar(arg1, numdays, vikudagur)
local pre = 1
local main = {}
table.insert(main, "<tr>")
while pre <= vikudagur do
table.insert(main, column() )
pre = 1 + pre
end
if vikudagur == 7 then
table.insert(main, row() )
end
local day = 1
for day = 1,numdays do
table.insert(main, column("[[" .. day .. ". " .. arg1 .. "|" .. day .. "]]") )
if math.fmod(table.maxn(main), 8) == 0 then
table.insert(main, row() )
end
day = 1 + day
end
table.insert(main, "</tr>")
return table.concat(main)
end
function column(text)
local td = mw.html.create("td")
td
:wikitext(text or "")
:done()
return tostring(td)
end
function row()
local tr = "</tr><tr>"
return tr
end
return p